5

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.

Martin Melka
  • 7,177
  • 16
  • 79
  • 138
  • Do I understand you right - you have two different pom files but they have the same GroupId ArtifactId Version and thus you get forbidden when deploying the second one ? – mediahype May 09 '16 at 13:32
  • 1
    Yes, that is correct.The name of the files is different (classifier), but the name of their pom.xml is the same -- I get the forbidden when pom.xml is being uploaded. – Martin Melka May 09 '16 at 13:35
  • It boils down to the following question: Are your *runtime*.jar files required at compile time ? Because from the name it does not look as though – mediahype May 09 '16 at 14:00
  • it is a misleading terminology, but yes, they are required for the compilation, so both compile and runtime dependency. – Martin Melka May 09 '16 at 14:12

1 Answers1

2

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>
user944849
  • 14,524
  • 2
  • 61
  • 83
mediahype
  • 480
  • 2
  • 8
  • I talked to the manager of the product I am refactoring this for, and we agreed to just use separate group/artifact for each runtime version. That way we get rid of the classifiers and it becomes much less of a fight against Maven. They will have to change a few things, but it seems to be worth it. Thank you for the answer though – Martin Melka May 10 '16 at 09:38