Gradle Artifactory Plugin - How To Publish Artifacts From Multiple Modules In A Project?
Solution 1:
Update: As of version 4.6.0
of the com.jfrog.artifactory Gradle plugin, publishing artifacts in a multi-module project just does not work. From personal experience, you're best just abandoning this plugin and using the standard maven-publish plugin for both Java library modules and Android library modules.
--- What follows below is my original answer before I posted the above update ---
So I've finally got this all working! Special thanks to @RaGe for helping me along the way. The key points to note are that the artifactory
block needs to be in the project's root-level build.gradle
file and not in the build.gradle
file of the individual modules. Also, you need to add artifactoryPublish.skip=true
to the project's root-level build.gradle
file. See this GitHub repo for a full-on yet minimal-as-possible example:
https://github.com/adil-hussain-84/SO-35851251-Multiproject-Artifactory-Publish
In case the link ever stops working I'll paste the contents of the build.gradle
files here also. Firstly, the project's root-level build.gradle
file:
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'
}
Secondly, the build.gradle
file of the Android
module:
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 {
defdependenciesNode= 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 {
defdependencyNode= dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
Thirdly and finally, the build.gradle
file of the SharedCode
(Java) module:
apply plugin: 'java'
apply plugin: 'maven-publish'
dependencies {
compile'com.google.guava:guava:18.0'
}
publishing {
publications {
SomePublication(MavenPublication) {
from components.java
}
}
}
That's it!
Solution 2:
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)
Solution 3:
Version 4.2.0 of the Gradle Artifactory Plugin was released last week and added multiple Artifactory repositories deployment. Now you can simply define an artifactory closure with a different repository for different modules of the project.
Post a Comment for "Gradle Artifactory Plugin - How To Publish Artifacts From Multiple Modules In A Project?"