Maven的每個(gè)工程默認(rèn)只會處理一個(gè)產(chǎn)物奕筐,這個(gè)從POM文件的結(jié)構(gòu)中也可以看出來。但是我們很多情況下一個(gè)工程中是有多個(gè)產(chǎn)物的,這種情況就需要去生成多個(gè)POM文件蝎困,然后顯示的聲明要上傳的每個(gè)產(chǎn)物
uploadArchives {
repositories {
mavenDeployer {
//關(guān)聯(lián)一個(gè)Maven庫
repository(url: "file://localhost/tmp/myRepo/")
addFilter('api') {artifact, file ->
artifact.name == 'api'
}
addFilter('service') {artifact, file ->
artifact.name == 'service'
}
pom('api').version = 'mySpecialMavenVersion'
}
}
}
if there is only one artifact, usually there is not more to do. If there is more than one artifact you have to decide what to do about this, as a Maven POM can only deal with one artifact. There are two strategies. If you want to deploy only one artifact you have to specify a filter to select this artifact. If you want to deploy more than one artifact, you have to specify filters which select each artifact. Associated with each filter is a separate configurable POM.
POM文件MavenPom
Pom文件最終在
<buildDir>/poms
中上生成
Android中使用
MavenDeployer 默認(rèn)只上傳Release產(chǎn)物,如果增加了變體則需要在artifacts中聲明需要上傳的產(chǎn)物倍啥,因?yàn)橛卸鄠€(gè)產(chǎn)物禾乘,需要通過addFiller配置POM去給對應(yīng)變體顯示聲明需要上傳的產(chǎn)物,比如debug變體只上傳debug的產(chǎn)物
apply plugin: 'maven'
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
...
//關(guān)鍵代碼
android.libraryVariants.all { variant ->
def isFlavor = !variant.flavorName.isEmpty()
def variantName = "${variant.name}"
artifacts {
if ("debug"==variantName) {
archives file: file("build/outputs/aar/${project.name}-${variantName}.aar")
}
archives sourcesJar
}
addFilter(variantName) { artifact, file ->
println file.name + "=$variantName"
//選取產(chǎn)物
file.name.contains(variantName)
}
pom(variantName).groupId = GROUP
pom(variantName).artifactId = POM_ARTIFACT_ID + "-" + variantName
pom(variantName).version = getVersionName()
pom(variantName).project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
}
...
}
}
}
}
}
}