1
votes

I've been struggling with this for quite some while.

Background: We have some Jenkins jobs that produce jars and other jobs that upload the jars to nexus. In our case we are looking for myJar-1.0.jar and myJar-1.0-myClassifier.jar. Obviously they are both produced with the same pom.xml file.

What I am trying to achieve is to upload both of them on Nexus (We use Nexus2) through the REST API with a curl command using the pom.xml. The pom.xml file looks something like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.group.id</groupId>
    <artifactId>myJar</artifactId>
    <version>1.0</version>
    <name>My Name</name>
    <packaging>pom</packaging>
    <properties>
          <otherJar.version>1.5</otherJar.version>
          ...
    </properties>
    <dependencies>
          <dependency>
                    <groupId>x.y</groupId>
                    <artifactId>art</artifactId>
                    <version>{$otherJar.version}</version>
          </dependency>
          ...
    </dependencies>
</project>

The curl command that I'm using to upload (the jar without the classifier) is:

curl -v -F r=releases -F hasPom=true -F e=jar -F [email protected] -F [email protected] -u user:pass http://link/to/nexus/service/local/artifact/maven/content

and this works as expected. The jar is uploaded to nexus with the groupid, artifactid and version mentioned in the pom.xml file.


My question is - after I upload this jar, how can I upload the jar with the classifier provided we have the same pom.xml?

  • Should I alter the pom.xml file? If so, how?
  • Should I modify the curl command? I tried adding -F c=myClassifier but that didn't work. That resulted in an error produced by Nexus: <html><body><error>Repository with ID='releases' does not allow updating artifacts.</error></body></html> (because there is already an artifact with same groupid, artifactid and version - the one that I just uploaded; it seems that the classifier is ignored)
1
Why do you have separate jobs to build and deploy in Jenkins. Maven can do the deploy without any problems and everything will work... no hassle with Curl etc.khmarbaise
The short response to this question would be - it's complicated :) I tried to simplify the context as much as I could in order to ask the question. Unfortunately we can't change the way the jobs are defined at the moment.Marius Manastireanu
All artifacts and the pom should be uploaded in one shot. Since this is NXRM 2 you can use the UI to test this while watching the HTTP traffic to figure out the right parameters: blog.sonatype.com/…rseddon

1 Answers

1
votes

So I tried multiple solutions and could not come up with one that satisfies my needs (uploads multiple jars with the same pom and different classifiers through the REST API) with one or more calls.

I ended up installing maven on the machine that was running my scripts and using the maven deploy:deploy-file as follows:

maven deploy:deploy-file
    -DpomFile=pom.xml
    -Dfile=myJar-1.0.jar
    -Dpackaging=jar                    // this doesn't have to be specified, it will be taken from the pom file, however in my case the pom was specifying <packaging>pom</packaging> and the jar ended up with .pom extention
    -Dclassifiers=myClassifier         // here you can define multiple classifiers, comma-separated
    -Dtypes=jar                        // same as above
    -Dfiles=myJar-1.0-myClassifier.jar // same as above
    -DrepositoryId=nexus
    -Durl=http://host:port/nexus/content/repositories/releases

You can find the full documentation here.

Also, please note that you have to define your nexus repository credentials in the maven's configuration file (maven_home/conf/settings.xml). Find the node servers in that file and add something similar to this:

    <server>
      <id>nexus</id>
      <username>yourUserName</username>
      <password>yourPass</password>
    </server>

In the end I want to stress the fact that I think this is a missing feature/bug of Nexus2's REST API. As you can see from the snippet above, this can be achieved by uploading the jars with maven and this can also be achieved manually from the Nexus interface. However, I did not manage to do it through the REST API. It could be possible because I did not find the right way to call it, but I couldn't find (almost) any documentation either.. a bummer.

Also, final note for this question - I will leave this unsolved since this does not answer my original question (How can this be achieved through the REST API?).