简体   繁体   English

在Maven Repo中存储Java 5和Java 6 JAR

[英]Store java 5 and java 6 JARs in Maven Repo

I think I need to store both Java 5 and Java 6 versions of the same jar in our internal Maven repository (Nexus). 我想我需要在我们的内部Maven存储库(Nexus)中存储同一jar的Java 5和Java 6版本。 How? 怎么样?

I thought that I might be able to specify a classifier in the deploy plugin config ... 我以为我可以在deploy插件配置中指定分类器...

<build>
    <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <classifier>${jvmClassifier}</classifier>
            </configuration>
        </plugin>

but it is ignored! 但是它被忽略了!

You should use the version attribute, ie if you have both Java 5 and 6 jars of the version 2.1, then the "full" version will be 2.1-jdk15 and 2.1-jdk16. 您应该使用version属性,即,如果同时具有2.1版本的Java 5和6个jar,则“完整”版本将为2.1-jdk15和2.1-jdk16。 UISpec4J uses this approach - uispec4j-2.3-jdk16.jar and uispec4j-2.3-jdk15.jar UISpec4J使用这种方法-uispec4j-2.3-jdk16.jar和uispec4j-2.3-jdk15.jar

You can obtain different builds for different versions of the Java platfom, using different Maven profiles that specify the compiler versions for the maven compiler plugin (1.5 in one, and 1.6 in another). 您可以使用不同的Maven配置文件为Java platfom的不同版本获得不同的版本,这些配置文件为maven编译器插件指定了编译器版本(一个为1.5,另一个为1.6)。 A hint is provided in the Sonatype book titled " Maven - The Complete Reference ". Sonatype书中提供了一个提示,标题为“ Maven-完整参考 ”。

For the purpose of distinguising the JARs from each other, the other answer provides a really good hint. 为了彼此区分JAR, 另一个答案提供了一个很好的提示。 If you wish to achieve the same, you'll need to tweak the jar:jar task in each of the profiles to generate different jars that can then be deployed to the local repository. 如果要达到相同的目的,则需要在每个配置文件中调整jar:jar任务,以生成不同的jar,然后将其部署到本地存储库。

It is ignored because classifier is NOT a parameter of deploy:deploy which is the goal bound to the deploy phase (it's a parameter of deploy:deploy-file though). 它被忽略,因为classifier器不是deploy:deploy的参数,这是绑定到deploy阶段的目标(尽管它是deploy:deploy-file的参数)。

Put the classifier in the configuration of the jar/war/ear plugin. 将分类器放入jar / war / ear插件的配置中。 Here is a pom.xml simulating the desired behavior (you should probably use profiles): 这是一个模拟所需行为的pom.xml (您可能应该使用配置文件):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <properties>
    <jvmClassifier>jdk16</jvmClassifier>
  </properties>
  <groupId>com.stackoverflow.q3341837</groupId>
  <artifactId>Q3341837</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>Q3341837</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.1</version>
        <configuration>
          <classifier>${jvmClassifier}</classifier>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <altDeploymentRepository>mine::default::file://${basedir}/target/my-repo</altDeploymentRepository>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Here is what I get after running mvn deploy : 这是运行mvn deploy之后得到的结果:

$ mvn clean deploy
...
$ tree target/my-repo/
target/my-repo/
└── com
    └── stackoverflow
        └── q3341837
            └── Q3341837
                ├── 1.0-SNAPSHOT
                │   ├── maven-metadata.xml
                │   ├── maven-metadata.xml.md5
                │   ├── maven-metadata.xml.sha1
                │   ├── Q3341837-1.0-20100727.222050-1.pom
                │   ├── Q3341837-1.0-20100727.222050-1.pom.md5
                │   ├── Q3341837-1.0-20100727.222050-1.pom.sha1
                │   ├── Q3341837-1.0-SNAPSHOT-jdk16.jar
                │   ├── Q3341837-1.0-SNAPSHOT-jdk16.jar.md5
                │   └── Q3341837-1.0-SNAPSHOT-jdk16.jar.sha1
                ├── maven-metadata.xml
                ├── maven-metadata.xml.md5
                └── maven-metadata.xml.sha1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM