Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven deploy two jars with different classifiers from two separate pom.xml

Tags:

java

maven

I want to deploy two jar artifacts with different classifiers, but at the moment that fails because both supply their own version of pom.xml. How can I fix that, so that both pom.xmls can be uploaded along with their artifacts?

Example - I have com.test.company.somelib-1.0.0-cmp1.jar and com.test.company.somelib-1.0.0-cmp2.jar, where cmpX is a classifier. Both packages contain (logically) the same code and classes (of the same version), they only differ slightly in the way they were preprocessed. The classifier annotation is there due to backwards compatibility we need to maintain.

Long story short, first artifact uploads fine, second one fails with Forbidden, because our repository does not allow overwriting artifacts (and I want to keep it that way).

There is a slightly different pipeline that creates both the packages, so it is easier to have their builds separate. I just want to deploy them as two packages of the same name and different classifier.

Thanks for help


Edit: it has been suggested to use Maven profiles. I can see that they would work, but they would not be ideal.

Consider the setup I have depicted on the picture below - there is a CI server (TeamCity).

  • There is a "starter" build (Sources). This build checkouts all required source files.
  • From this starter build several other builds are triggered (processing using x.x.x/compile). Each of those builds adjusts a template-pom.xml (fills in particular classifier and other info), and then builds and deploys its artifact to our Artifactory.

enter image description here

With the setup I want to achieve if I decide to add another processing-build, all I need to do is add another "branch". If I was using profiles, I would need to also add a new profile to the pom.xml file.

Correct me if I am wrong please. Profiles seem to be able to achieve the goal, but not ideally, at least in my case.

like image 204
Martin Melka Avatar asked Oct 31 '22 03:10

Martin Melka


1 Answers

I strongly discourage having 2 (or more) different pom files with the same GAV.

But I understand your need is raised by legacy reasons. I have not tried this myself but it could be working: Leave one build (= maven project) as you have it now. On the other build skip the normal deployment and manually invoke the deploy-file goal of the deploy plugin like so:

<build>
  <plugins>
     <!-- skip normal execution of deploy plugin -->
     <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <executions>
           <execution>
              <id>default-deploy</id>
              <configuration>
                  <skip>true</skip>
              </configuration>
           </execution>
        </executions>
     </plugin>

     <!-- invoke with goal: deploy-file -->
     <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <executions>
           <execution>
              <id>someId</id>
              <phase>deploy</phase>
              <goals>
                 <goal>deploy-file</goal>
              </goals>
              <inherited>false</inherited>
              <configuration>
                 <file>path-to-your-artifact-jar</file>
                 <generatePom>false</generatePom>
                 <artifactId>xxx</artifactId>
                 <groupId>xxx</groupId>
                 <version>xxx</version>
                 <classifier>xxx</classifier>
                 <packaging>xxx</packaging>
              </configuration>
           </execution>
        </executions>
     </plugin>
  </plugins>
</build>
like image 143
mediahype Avatar answered Nov 15 '22 04:11

mediahype