How to manage artifactory / maven artifact using different profiles

独自空忆成欢 提交于 2020-01-15 03:32:33

问题


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.


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!