6

I am successfully building my gradle project in Jenkins and deploying the jars to artifactory. However when I try to reuse them in another project the additional dependencies are not recognized/downloaded. I presume this has to do with the missing pom file in artifactory.

In artifactory the JAR files are correctly uploaded but there is no POM file next to it.

Am I correct in understanding that I need this POM file for gradle to resolve the jar's dependecies when trying to download it again? And why is the POM file not generated?

The job settings are:

Gradle-Artifactory Integration

Project uses the Artifactory Gradle Plugin = false
Capture and publish build info = true
Publish artifacts to Artifactory = true
    Publish Maven descriptors = true
Use Maven compatible patterns = true
    patterns are default: [organization]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]

Build:

use gradle wrapper = true
tasks = build
2
  • How is the jar uploaded to Artifactory? Via mvn deploy or via Artifactory Jenkins Plugin? Jan 5, 2016 at 16:04
  • it is uploaded via the Artifactory Jenkins Plugin
    – p.streef
    Jan 5, 2016 at 18:23

2 Answers 2

14

A Maven repository indeed provides artefacts (normally jar files) and pom files (.pom extension) listing the required dependencies and their scope (so that they can transitively resolved to recreate the whole required dependency graph per each artefact). So indeed you would need the jar and the .pom file.

I had exactly the same issue but for a maven build. In my case the Jenkins build was executing the mvn clean package command, which effectively creates the desired jar file. Then the Artifactory Jenkins Plugin was correctly pushing the jar to Artifactory, perfectly available with the desired Maven coordinates (GAV, groupId, artifactId, version). However, the .pom file was missing.
In my case, solution was to change the invoked Maven phase, from package to install. The install phase indeed creates also the desired .pom file and additionally installs the artefact on the local repository (the Maven cache).

So, simply switching to mvn clean install, the Artifactory Jenkins Plugin was correctly uploading .jar and .pom file.

In your case, for a gradle build the issue could potentially be the same. You are probably creating the expected jar file and the Artifactory Jenkins Plugin is correctly picking it up and pushing it to Artifactory, but no .pom file is generated and as such not uploaded. So, if you are invoking gradle assemble or gradle build you are correctly generating the jar, but not the .pom file. You should probably also execute on the Jenkins build a gradle install command using the maven plugin as explained in this other SO answer and by the plugin documentation, from which we can also read:

31.6.3. Installing to the local repository
The Maven plugin adds an install task to your project. This task depends on all the archives task of the archives configuration. It installs those archives to your local Maven repository.

31.6.4. Maven POM generation
When deploying an artifact to a Maven repository, Gradle automatically generates a POM for it.

Beware though that "While the maven plugin does provide the install task, it only adds the task in the presence of the java plugin". Alternatively, to create the .pom file, you could also consider the maven-publish plugin and its publishToMavenLocal task.

So, to summarize: to properly create .jar and .pom file, you need to install the artefact on the local cache (in your case: the local cache of the Jenkins server, an harmless action), because as part of this process the required files are created as output of the build. The Artifactory Jenkins Plugin will then pick them up and properly upload them.

Update
Alternatively and as described in the comments below (and in another SO question), you could also avoid the install step and rather add a createPom task to your gradle build, in order to create the POM file as following:

task createPom << { 
    pom { 
        project { 
            groupId 'company'
            artifactId project.name
            version "$version"
        }
    }.writeTo("pom.xml")
}
3
  • 1
    Close enough! Instead of installing I have added a createPom task myself, which I now added to running along the build. This creates the POM file and now I can correctly compile the artifacts in my other project task createPom << { pom { project { groupId 'company' artifactId project.name version "$version" } }.writeTo("pom.xml") }
    – p.streef
    Jan 6, 2016 at 7:44
  • 1
    Great, well done. I will update the answer accordingly then to give it more visibility. Jan 6, 2016 at 10:36
  • 1
    Maybe it's worth mentioning that the left shift operator (<<) is currently deprecated and is about to be completely removed from version 5.0. :) Oct 30, 2017 at 9:11
0

What helped me was adding the following configuration:

Include Patterns: *.pom *.jar

There also should be enabled maven plugin in build.gradle:

apply plugin: 'maven-publish'

After that generated pom and artifacts were successfully uploaded by Jenkins job to Artifactory. Make sure that Publish Maven descriptors flag is set to true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.