我有一个项目,它有SharedCode
(Java)模块,其次是Android
(Android库)模块,它取决于SharedCode
模块。我想从jar
模块发布SharedCode
工件,从aar
模块发布Android
工件。我无法弄清楚如何编写我的build.gradle
文件,以便在artifactoryPublish
任务运行时两个模块都发布到Artifactory。目前只有SharedCode
模块将其工件发布到Artifactory。
我的build.gradle
文件如下。请注意,maven-publish
文件的build.gradle
方面似乎是正确的,因为当我运行publishToMavenLocal
任务时,我会看到本地Maven文件夹中两个模块的工件(即{{1} })。
首先,我'~/.m2/repository'
模块中的build.gradle
文件如下:
SharedCode
其次,我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
}
}
}
模块中的build.gradle
文件如下:
Android
如果我在根目录,项目级别或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
}
}
}
模块级别运行artifactoryPublish
任务,那么我看到输出如下:
SharedCode
请注意,在这种情况下只发布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
模块级别运行artifactoryPublish
任务,那么我看到输出如下:
Android
请注意,在这种情况下不会发布任何工件。
答案 0 :(得分:5)
更新:自
4.6.0
Gradle插件版本com.jfrog.artifactory
发布多模块项目中的发布工件 不行。从个人经验来看,你最好放弃这个 插件并使用Java库的标准maven-publish
插件 模块和Android的digital.wup.android-maven-publish
插件 图书馆模块。
所以我终于把这一切都搞定了!特别感谢@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
文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.0.1'
}
}
allprojects {
apply plugin: 'com.jfrog.artifactory'
repositories {
jcenter()
}
group = "${projectGroupName}"
version = "${projectVersionName}"
}
artifactoryPublish.skip=true
artifactory {
contextUrl = "${artifactory_url}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_username}"
password = "${artifactory_password}"
}
defaults {
publications('SomePublication')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.8'
}
其次,build.gradle
模块的Android
文件:
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
versionCode Integer.parseInt("${projectVersionCode}")
versionName "${projectVersionName}"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile project(':SharedCode')
compile 'com.android.support:appcompat-v7:23.2.1'
testCompile 'junit:junit:4.12'
}
publishing {
publications {
SomePublication(MavenPublication) {
artifact "$buildDir/outputs/aar/Android-release.aar"
//The publication doesn't know about our dependencies, so we have to manually add them to the pom
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.compile.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
第三个也是最后一个build.gradle
(Java)模块的SharedCode
文件:
apply plugin: 'java'
apply plugin: 'maven-publish'
dependencies {
compile 'com.google.guava:guava:18.0'
}
publishing {
publications {
SomePublication(MavenPublication) {
from components.java
}
}
}
就是这样!
答案 1 :(得分:3)
Gradle Artifactory插件版本4.2.0于上周发布,并添加了多个Artifactory存储库部署。现在,您只需为项目的不同模块定义具有不同存储库的工件闭包。
答案 2 :(得分:2)
通过github repo上的神器多项目示例,似乎只有根项目需要有一个artifactory{...}
配置部分,而不是像你所做的那样在每个子项目中。
此外,当您在根项目中声明publications('SharedCode')
时,artifactory插件似乎在每个子项目中寻找名为sharedCode
的发布。
我会尝试:
从android build.gradle
artifactory{...}
部分
将android出版物重命名为sharedCode
(或两个项目中更通用的内容)