Gradle Artifactory插件 - 如何发布项目中多个模块的工件? [英] Gradle Artifactory Plugin - How to publish artifacts from multiple modules in a project?
问题描述
我有一个项目有一个 SharedCode
(Java)模块,其次是 Android
(Android库)模块这取决于 SharedCode
模块。我想从 SharedCode
模块发布一个 jar
工件,以及一个 aar
artifact来自 Android
模块。我不知道如何编写我的 build.gradle
文件,以便两个模块在 artifactoryPublish
时发布到Artifactory。任务运行。目前只有 SharedCode
模块将其工件发布到Artifactory。
<我的
构建。 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 {
编译'com.google.guava:guava:18.0'
}
发布{
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 ...
}
依赖关系{
编译项目(':SharedCode')
}
发布{
publications {
Android(MavenPublication){
groupId$ {projectGroupId}
artifactId'Android'
版本$ {projectVersionName}
artifact$ buildDir / outputs / aar / Android-release.aar
}
}
artifactory {
contextUrl =$ {artifactory_url}
发布{
repository {
repoKey ='libs-release-local'
username =$ {artifactory_username}
password =$ {artifactory_password}
}
默认值{
出版物('Android')
publishArtifacts = true
properties = ['qa.level':'basic','dev.team':'core']
publishPom = true
}
}
}
如果我运行 artifactoryPublish 任务在根目录,项目级别或
SharedCode
模块级别,然后我看到如下输出:
18:23:38:执行外部任务'artifactoryPublish'...
'项目'不存在'SharedCode':Android' :安卓:artifactoryPublish。
:SharedCode:generatePomFileForSharedCodePublication
:SharedCode:artifactoryPublish
部署工件:http:// localhost:8081 / artifactory / libs-release-local / com / mycompany / sdk / SharedCode / 0.0.2 /SharedCode-0.0.2.jar
部署工件:http:// localhost:8081 / artifactory / libs-release-local / com / mycompany / sdk / SharedCode / 0.0.2 / SharedCode-0.0.2.pom
将构建描述符部署到:http:// localhost:8081 / artifactory / api / build构建已成功部署。
在Artifactory中的http:// localhost:8081 / artifactory / webapp / builds / client-sdk / 1457375019604
建立成功
注意在这种情况下只发布 SharedCode
工件。
如果我在 Android
模块级别运行 artifactoryPublish
任务,那么我看到输出为如下所示:
18:25:25:执行外部任务'artifactoryPublish'...
名为'SharedCode'不存在项目':Android'在任务':Android:artifactoryPublish'。
:Android:artifactoryPublish
将构建描述符部署到:http:// localhost:8081 / artifactory / api / build
构建成功部署。在http:// localhost:8081 / artifactory / webapp / builds / client-sdk / 1457375127269
建立成功
请注意,在这种情况下不会出现任何工件。
在他们的github repo上有一些artifactory多项目的例子,似乎只有根项目需要有一个 artifactory {...}
配置部分,项目,如你所做的那样。
此外,当您在根项目中声明 publications('SharedCode')
时,artifactory插件似乎要在每个子项目中寻找一个名为 sharedCode
的发布。
我会尝试: 移除 将android发布重命名为
artifactory {...}
从android build.gradle开始
sharedCode
(或者在两个项目中更通用)
I have a project which has a SharedCode
(Java) module and secondly an Android
(Android library) module which depends on the SharedCode
module. I want to publish a jar
artifact from the SharedCode
module and an aar
artifact from the Android
module. I can't figure out how to compose my build.gradle
files so that both modules publish to Artifactory when the artifactoryPublish
task is run. At the moment only the SharedCode
module publishes its artifact to Artifactory.
My build.gradle
files are as below. Note that the maven-publish
aspect of my build.gradle
files appears to be correct because when I run the publishToMavenLocal
task I see the artifacts from both modules in my local Maven folder (i.e. '~/.m2/repository'
).
Firstly, the build.gradle
file in my SharedCode
module is as follows:
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
}
}
}
Secondly, the build.gradle
file in my Android
module is as follows:
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
}
}
}
If I run the artifactoryPublish
task at the root, project level or at the SharedCode
module level then I see output as follows:
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
Note that only the SharedCode
artifact is published in this case.
If I run the artifactoryPublish
task at the Android
module level, then I see output as follows:
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
Note that no artifacts are published in this case.
Going by artifactory multi-project examples on their github repo, it would seem that only the root project needs to have an artifactory{...}
configuration section as opposed to in every sub-project as you have done.
Moreover when you declare publications('SharedCode')
in the root project, artifactory plugin seems to be looking for a publication called sharedCode
in every subproject.
I would try:
Remove the
artifactory{...}
section from the android build.gradleRename the android publication to
sharedCode
as well (or something more generic in both projects)
这篇关于Gradle Artifactory插件 - 如何发布项目中多个模块的工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!