2
votes

My project has two modules, lib and lib-api, with the following responsibilities

  • lib-api - a pure java module that only contains interface files
  • lib - an android library

and I'd like to jenkins publish both modules (as jars) to an internal artifactory server for other projects to be able consume.

Using the Jenkins Artifactory Plugin, I was able to publish jars for both modules to artifactory, but my other project that depends on lib fails to build with the following gradle error

Could not find com.mygroup:lib-api:1.0.0-SNAPSHOT

My setup

Build scripts

lib-api/build.gradle

apply plugin: 'java'
apply plugin: 'maven-publish'

group = 'com.mygroup'
version = project.version

publishing {
    publications {
        api(MavenPublication) {
            from components.java
        }
    }
}

lib/build.gradle

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

android { ... }

dependencies {
    compile project(':lib-api')
}

group = 'com.mygroup'
version = project.version

Jenkins Artifactory plugin config

  • Gradle-Artifactory Integration
    • Publish artifacts to Artifactory
      • Publish Maven descriptors
    • Use Maven compatible patterns
  • Invoke Gradle script
    • Use Gradle Wrapper
    • Tasks: clean assemble -x preDexDebug -x preDexDAT -x preDexRelease

Result in Artifactory repo

+-- libs-snapshot-local
|   +-- com
|   |   +-- mygroup
|   |   |   +-- lib
|   |   |   |   +-- 1.0.0-SNAPSHOT
|   |   |   |   |   `-- lib-1.0.0-20150508-1.jar
|   |   |   |   |   `-- lib-1.0.0-20150508-1.pom
|   |   |   |   |   `-- maven-metadata.xml
|   |   |   |   `-- maven-metadata.xml
|   |   |   +-- lib-api
|   |   |   |   +-- 1.0.0-SNAPSHOT
|   |   |   |   |   `-- lib-1.0.0-20150508-1.jar

Question

My understanding is that artifactory/gradle should be smart enough to resolve -SNAPSHOT into the latest timestamped snapshot and that seems to be borne out by the fact that it manages to resolve lib whether I specify latest.integration or 1.0.0-SNAPSHOT

How can I get gradle to resolve this transitive snapshot dependency from artifactory? Or get the artifactory plugin to publish the jar in such a way that gradle can resolve it?

Working theory

I noticed that the lib-api folder doesn't have a maven-metadata.xml file and the snapshot version folder doesn't have one either... or pom file. I suspect this might be the issue.

Artifactory's Jenkins plugin uses the gradle artifactory plugin under the hood for jobs that have Gradle-Artifactory integration enabled. According to the gradle artifactory plugin docs the plugin ID changes depending on whether you are using the new (maven-publish) or old (maven) publishing mechanism.

Could this be the issue? Is the Artifactory plugin applying the wrong plugin ID, perhaps because it is making it's decision based on the android library module?

1

1 Answers

2
votes

tl;dr Switching to the old maven plugin for gradle fixed it.

My lib-api/build.gradle now looks like this

apply plugin: 'java'
apply plugin: 'maven'

group = 'com.mygroup'
version = project.version
ext.artifactId = project.name.toLowerCase()
project.archivesBaseName = project.artifactId

uploadArchives {
    repositories {
        mavenDeployer {
            pom.artifactId = project.artifactId
        }
    }
}

Note: According to the gradle docs for the maven plugin, pom.artifactId must be explicitly defined if you've set archivesBaseName. That may have been the underlying issue with my previous configuration, but I did not go back and test it.