3

I'm trying to use the maven-shade-plugin to distinguish between Java 6 and Java 7 artifacts. My understanding from this link is that the original artifact will be replaced by the shaded one

[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing /Users/carlos/path/Libraries/xml/target/xml-1.5.0-SNAPSHOT.jar with /Users/carlos/path/Libraries/xml/target/xml-1.5.0-SNAPSHOT-SHADED.jar
[INFO] Replacing original test artifact with shaded test artifact.
[INFO] Replacing /Users/carlos/path/Libraries/xml/target/xml-1.5.0-SNAPSHOT-tests.jar with /Users/carlos/path/Libraries/xml/target/xml-1.5.0-SNAPSHOT-SHADED-tests.jar
[INFO] Dependency-reduced POM written at: /Users/carlos/path/Libraries/xml/dependency-reduced-pom.xml
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ xml ---
[INFO] Installing /Users/carlos/path/Libraries/xml/target/xml-1.5.0-SNAPSHOT.jar to /Users/carlos/.m2/repository/com/company/xml/1.5.0-SNAPSHOT/xml-1.5.0-SNAPSHOT.jar
[INFO] Installing /Users/carlos/path/Libraries/xml/dependency-reduced-pom.xml to /Users/carlos/.m2/repository/com/company/xml/1.5.0-SNAPSHOT/xml-1.5.0-SNAPSHOT.pom
[INFO] Installing /Users/carlos/path/Libraries/xml/target/xml-1.5.0-SNAPSHOT-tests.jar to /Users/carlos/.m2/repository/com/company/xml/1.5.0-SNAPSHOT/xml-1.5.0-SNAPSHOT-tests.jar
[INFO] Installing /Users/carlos/path/Libraries/xml/target/xml-1.5.0-SNAPSHOT-sources.jar to /Users/carlos/.m2/repository/com/company/xml/1.5.0-SNAPSHOT/xml-1.5.0-SNAPSHOT-sources.jar
[INFO] Installing /Users/carlos/path/Libraries/xml/target/xml-1.5.0-SNAPSHOT-tests.jar to /Users/carlos/.m2/repository/com/company/xml/1.5.0-SNAPSHOT/xml-1.5.0-SNAPSHOT-tests.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23.724 s
[INFO] Finished at: 2015-02-19T15:53:50-05:00
[INFO] Final Memory: 22M/631M
[INFO] ------------------------------------------------------------------------

However, it is installing without the SHADED classifier. Here is my shade plugin configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <shadeTestJar>true</shadeTestJar>
                <shadedClassifierName>SHADED</shadedClassifierName>
            </configuration>
        </execution>
    </executions>
</plugin>

Can anyone tell me how to get it to install with the proper classifier? Also, I'm using this instead of the maven-jar-plugin because I need to be able to classify test jars as well.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Carlos Bribiescas
  • 4,197
  • 9
  • 35
  • 66

1 Answers1

6

You are missing <shadedArtifactAttached>true</shadedArtifactAttached> in the plugin configuration. Without it, the shaded jar will remain the main artifact of your project, so the classifier won't be applied (because the main artifact does not have a classifier).

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <shadeTestJar>true</shadeTestJar>
                <shadedClassifierName>SHADED</shadedClassifierName>
                <shadedArtifactAttached>true</shadedArtifactAttached>
            </configuration>
        </execution>
    </executions>
</plugin>  
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • But that also creates the original artifact. So both are installed. I need to only deploy the classified version. I need to rename or "shade" the original artifact or else I'm double creating all the jars. – Carlos Bribiescas Feb 19 '15 at 21:45
  • It is not possible to have a classifier for a main Maven artifact. See [this](http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploying-with-classifiers.html). Besides, why would you want to do it ? Classifier are used to add additional artifacts to the project, like its sources or javadoc. – Tunaki Feb 19 '15 at 21:51
  • I need to shade the test created by the maven-jar-plugin to disinguish their Java version, but I also do not want to create an unclassified jar. Do you know how I could do this? – Carlos Bribiescas Feb 20 '15 at 18:31
  • As I said, you can not create a main artifact with a classifier. To distinguish different JDK versions, see [this answer](http://stackoverflow.com/a/3094466/1743880). – Tunaki Feb 20 '15 at 18:48
  • That doesn't work for the maven jar plugin. test-jar doesn't support classifiers – Carlos Bribiescas Feb 21 '15 at 05:17
  • I'm marking it as an answer because you're response answered the question as-posed, however there were some other nuances that I didn't specify as noted by the comments. Thanks – Carlos Bribiescas Oct 31 '16 at 20:34