tags:

views:

53

answers:

3

I think I need to store both Java 5 and Java 6 versions of the same jar in our internal Maven repository (Nexus). How?

I thought that I might be able to specify a classifier in the deploy plugin config ...

<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!

+1  A: 

You should use the version attribute, i.e. 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. UISpec4J uses this approach - uispec4j-2.3-jdk16.jar and uispec4j-2.3-jdk15.jar

ZloiAdun
No, you should not use the `version` attribute, you should use a `classifier` as the OP is trying to do.
Pascal Thivent
+1  A: 

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). A hint is provided in the Sonatype book titled "Maven - The Complete Reference".

For the purpose of distinguising the JARs from each other, the other answer provides a really good hint. 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.

Vineet Reynolds
+1  A: 

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).

Put the classifier in the configuration of the jar/war/ear plugin. Here is a pom.xml simulating the desired behavior (you should probably use profiles):

<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"&gt;
  <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&lt;/url&gt;
  <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 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
Pascal Thivent