Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Artifactory plugin not generating POM file

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
like image 609
p.streef Avatar asked Jan 05 '16 15:01

p.streef


People also ask

How do I use Jenkins Artifactory plugin?

Overview. To install the Jenkins Artifactory Plugin, go to Manage Jenkins > Manage Plugins, click on the Available tab and search for Artifactory. Select the Artifactory plugin and click Download Now and Install After Restart.

How do I download artifacts from Artifactory in Jenkins?

install the plugin (https://wiki.jenkins-ci.org/display/JENKINS/Artifactory+Plugin) on the job configuration page, enable "Generic Artifactory Integration". go to "Resolved Artifacts" and enter the artifacts to resolve/download - the question-mark icon on that page will tell you more about the syntax.

How do I publish artifacts to Artifactory using Maven?

Once you have created your Maven repository, go to Application | Artifactory | Artifacts, select your Maven repository and click Set Me Up. In the Set Me Up dialog, click Generate Maven Settings. You can now specify the repositories you want to configure for Maven.

How do you deploy a jar file in Jfrog Artifactory using Jenkins?

Simply install the Jenkins Artifactory plugin, configure the Artifactory repository within the Jenkins tool and then include deployment to the Artifactory repository as one of the Jenkins build steps. The Jenkins Artifactory plugin is easily integrated into Jenkins build jobs.


1 Answers

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")
}
like image 107
A_Di-Matteo Avatar answered Sep 29 '22 14:09

A_Di-Matteo