问题
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:
- Using Profile1 is compiling using java 7 and with dependency other:project:1.0
- 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:
- A Project require my.project:sample:1.0 - Profile1"
- 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.
回答1:
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>
来源:https://stackoverflow.com/questions/15433238/how-to-manage-artifactory-maven-artifact-using-different-profiles