Question

i have some problems understanding how to manage different "jar" files generated using different profiles. An example. I have a project : my.project:sample:1.0 And we use two profiles:

  1. Using Profile1 is compiling using java 7 and with dependency other:project:1.0
  2. Using Profile2 is compiling using java 6 and with dependency different:project:3.0

Using command line in local environment is easy to manage, but I don't know how to store and manage it on artifactory.

We have two different projects that use the same library but generated using different profiles:

  1. A Project require my.project:sample:1.0 - Profile1"
  2. Another project require my.project:sample:1.0 - Profile2"

How can I specify those depedency with the library and the profile?

Clarification: The generated Jar it's storing using artifactory, and the projects resolve the dependencies using the repository. I can't use the project as a module.

Was it helpful?

Solution

You can use classifier to make the distinction between artifacts and reuse the classifier in the dependency.

defining a classifier

To do so you need to define the classifier in maven-jar-plugin:

<profiles>
     <profile>
         <id>profile1</id>
         ...
         <build>
             <plugins>
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-jar-plugin</artifactId>
                     <version>2.4</version>
                     <executions>
                       <execution>
                       <phase>package</phase>
                       <goals>
                         <goal>jar</goal>
                       </goals>
                       <configuration>
                          <classifier>jdk6</classifier>
                       </configuration>
                      </execution>
                     </executions>
                 <plugin>
             <plugins>
         </build>
     </profile>
     <profile>
         <id>profile2</id>
         ...
         <build>
             <plugins>
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-jar-plugin</artifactId>
                     <version>2.4</version>
                     <executions>
                       <execution>
                       <phase>package</phase>
                       <goals>
                         <goal>jar</goal>
                       </goals>
                       <configuration>
                          <classifier>jdk7</classifier>
                       </configuration>
                      </execution>
                     </executions>
                 <plugin>
             <plugins>
         </build>
     </profile>
</profiles>

using the classifier in dependency

Very simple:

<dependency>
    <groupId>myGroup</groupId>
    <artifactId>myArtifact</artifactId>
    <classifier>jdk6</classifier>
<dependency>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top