Я пытаюсь загрузить несколько артефактов в проекте с плагином maven gradle:
http://www.gradle.org/docs/current/userguide/maven_plugin.html
53.6.4.1. Multiple artifacts per project
Maven can only deal with one artifact per project. This is reflected in the structure of the Maven POM. We think there are many situations where it makes sense to have more than one artifact per project. In such a case you need to generate multiple POMs. In such a case you have to explicitly declare each artifact you want to publish to a Maven repository. The MavenDeployer and the MavenInstaller both provide an API for this:
Example 53.9. Generation of multiple poms
build.gradle
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://localhost/tmp/myRepo/")
addFilter('api') {artifact, file ->
artifact.name == 'api'
}
addFilter('service') {artifact, file ->
artifact.name == 'service'
}
pom('api').version = 'mySpecialMavenVersion'
}
}
}
You need to declare a filter for each artifact you want to publish. This filter defines a boolean expression for which Gradle artifact it accepts. Each filter has a POM associated with it which you can configure. To learn more about this have a look at PomFilterContainer and its associated classes.
На самом деле я пытаюсь загрузить разные архивы для разных вариантов моей сборки.
Вот мои проекты build.gradle file:
apply plugin: 'com.android.library'
apply plugin: 'maven'
group 'com.test'
version '0.0.1'
android {
compileSdkVersion 19
buildToolsVersion "21.1.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
abortOnError false
}
productFlavors {
flavor1 { }
flavor2 { }
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${System.properties['user.home']}/.m2/repository")
addFilter('debugFlavor1') { artifact, file ->
artifact.name.contains("debugFlavor1")
}
addFilter('releaseFlavor1') { artifact, file ->
artifact.name.contains("releaseFlavor1")
}
addFilter('debugFlavor2') { artifact, file ->
artifact.name.contains("debugFlavor2")
}
addFilter('releaseFlavor2') { artifact, file ->
artifact.name.contains("releaseFlavor2")
}
pom('debug').artifactId = ${artifactId} + "-" ${flavor} + "-debug"
pom('release').artifactId = ${artifactId} + "-" ${flavor}
}
}
}
dependencies {
compile 'com.android.support:support-v4:21.0.2'
compile 'org.apache.commons:commons-lang3:3.3.2'
}
Возможно ли подобное?
Как мне получить атрибут artifactId и вкуса в каждом издании? Я использовал ${artifactId} и ${flavor} в качестве заполнителей, но я знаю, что это неправильно.
EDIT:
Хорошо, я понял, как получить другой артефакт для каждого аромата. Одним из ключей было установить:
publishNonDefault true
Однако, когда я это делаю, я не получаю файл pom для каждого артефакта. У меня есть транзитивные зависимости, которые нужно втянуть, и я не думаю, что они будут втянуты без помпы.
Вот мой текущий gradle script, как я могу получить pom для каждого.
apply plugin: 'com.android.library'
apply plugin: 'maven'
group 'com.test'
version '0.0.1'
android {
compileSdkVersion 19
buildToolsVersion "21.1.1"
publishNonDefault true
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
abortOnError false
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}
productFlavors {
flavor1 {}
flavor2 {}
}
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${System.properties['user.home']}/.m2/repository")
addFilter('flavor1Release') { artifact, file ->
artifact.attributes.classifier.equals("flavor1Release")
}
addFilter('flavor2Release') { artifact, file ->
artifact.attributes.classifier.equals("flavor2Release")
}
pom('flavor1Release').artifactId = project.archivesBaseName + "-flavor1"
pom('flavor2Release').artifactId = project.archivesBaseName + "-flavor2";
}
}
}
dependencies {
compile 'com.android.support:support-v4:21.0.2'
compile 'org.apache.commons:commons-lang3:3.3.2'
}