我有一个项目有一个 SharedCode
(Java)模块,其次是 Android
(Android库)模块,它取决于 SharedCode
模块 . 我想从 SharedCode
模块发布 jar
工件,从 Android
模块发布 aar
工件 . 我无法弄清楚如何编写我的 build.gradle
文件,以便在运行 artifactoryPublish
任务时两个模块都发布到Artifactory . 目前只有 SharedCode
模块将其工件发布到Artifactory .
我的 build.gradle
文件如下 . 请注意,我的 build.gradle
文件的 maven-publish
方面似乎是正确的,因为当我运行 publishToMavenLocal
任务时,我会看到本地Maven文件夹中两个模块的工件(即 '~/.m2/repository'
) .
首先,我的 SharedCode
模块中的 build.gradle
文件如下:
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
group = "${projectGroupId}"
version = "${projectVersionName}"
dependencies {
compile 'com.google.guava:guava:18.0'
}
publishing {
publications {
SharedCode(MavenPublication) {
groupId "${projectGroupId}"
artifactId 'SharedCode'
version "${projectVersionName}"
from components.java
}
}
}
artifactory {
contextUrl = "${artifactory_url}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_username}"
password = "${artifactory_password}"
}
defaults {
publications('SharedCode')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
}
其次,我的 Android
模块中的 build.gradle
文件如下:
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
group = "${projectGroupId}"
version = "${projectVersionName}"
android {
// android stuff here...
}
dependencies {
compile project(':SharedCode')
}
publishing {
publications {
Android(MavenPublication) {
groupId "${projectGroupId}"
artifactId 'Android'
version "${projectVersionName}"
artifact "$buildDir/outputs/aar/Android-release.aar"
}
}
}
artifactory {
contextUrl = "${artifactory_url}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_username}"
password = "${artifactory_password}"
}
defaults {
publications('Android')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
}
如果我在根目录,项目级别或 SharedCode
模块级别运行 artifactoryPublish
任务,那么我看到输出如下:
18:23:38: Executing external task 'artifactoryPublish'...
Publication named 'SharedCode' does not exist for project ':Android' in task ':Android:artifactoryPublish'.
:SharedCode:generatePomFileForSharedCodePublication
:SharedCode:artifactoryPublish
Deploying artifact: http://localhost:8081/artifactory/libs-release-local/com/mycompany/sdk/SharedCode/0.0.2/SharedCode-0.0.2.jar
Deploying artifact: http://localhost:8081/artifactory/libs-release-local/com/mycompany/sdk/SharedCode/0.0.2/SharedCode-0.0.2.pom
Deploying build descriptor to: http://localhost:8081/artifactory/api/build Build successfully deployed.
Browse it in Artifactory under http://localhost:8081/artifactory/webapp/builds/client-sdk/1457375019604
BUILD SUCCESSFUL
请注意,在这种情况下仅发布 SharedCode
工件 .
如果我在 Android
模块级别运行 artifactoryPublish
任务,那么我看到输出如下:
18:25:25: Executing external task 'artifactoryPublish'...
Publication named 'SharedCode' does not exist for project ':Android' in task ':Android:artifactoryPublish'.
:Android:artifactoryPublish
Deploying build descriptor to: http://localhost:8081/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://localhost:8081/artifactory/webapp/builds/client-sdk/1457375127269
BUILD SUCCESSFUL
请注意,在这种情况下不会发布任何工件 .
3 回答
通过他们的github仓库中的神器多项目示例,似乎只有根项目需要有一个
artifactory{...}
配置部分,而不是像你所做的那样在每个子项目中 .此外,当您在根项目中声明
publications('SharedCode')
时,artifactory插件似乎在每个子项目中寻找名为sharedCode
的发布 .我会尝试:
从android build.gradle中删除
artifactory{...}
部分将android出版物重命名为
sharedCode
(或两个项目中更通用的东西)所以我终于把这一切都搞定了!特别感谢@RaGe帮助我一路走来 . 需要注意的关键点是
artifactory
块需要位于项目的根级build.gradle
文件中,而不是位于各个模块的build.gradle
文件中 . 此外,您需要将artifactoryPublish.skip=true
添加到项目的根级build.gradle
文件中 . 请参阅此GitHub仓库以获取完整的,尽可能最小的示例:https://github.com/adil-hussain-84/SO-35851251-Multiproject-Artifactory-Publish
如果链接停止工作,我也会在这里粘贴
build.gradle
文件的内容 . 首先,项目的根级build.gradle
文件:其次,
Android
模块的build.gradle
文件:第三,也是最后一个
SharedCode
(Java)模块的build.gradle
文件:而已!
Gradle Artifactory插件版本4.2.0于上周发布,并添加了多个Artifactory存储库部署 . 现在,您可以简单地为项目的不同模块定义具有不同存储库的工件闭包 .