Search code examples
mavenjarmaven-jar-plugin

Remove tests classifier of Maven jar:test-jar goal?


I have configured the maven-jar-plugin as follow:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <version>2.3.2</version>
  <configuration>
    <finalName>${project.artifactId}.main</finalName>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>test-jar</goal>
      </goals>
      <configuration>
        <finalName>${project.artifactId}.tests</finalName>
      </configuration>
    </execution>
  </executions>
</plugin>

I want my output JAR files to be called ARTIFACT.main.jar and ARTIFACT.tests.jar. The former is working, but the later comes out as ARTIFACT.tests-tests.jar instead. Is there any way to adjust the above configuration to remove the -tests classifier?


Solution

  • Unfortunately, after looking at the maven-jar-plugin source code, I don't think it is possible to remove the tests classifier from the test jar.

    The execute method that is called during the goal test-jar takes the output of the method getClassifier() to append a classifier:

    File jarFile = createArchive();
    String classifier = getClassifier();
    if ( classifier != null )
    {
        projectHelper.attachArtifact( getProject(), getType(), classifier, jarFile );
    }
    else
    {
        getProject().getArtifact().setFile( jarFile );
    }
    

    and the getClassifier() method returns the hard-coded String "tests" for the test-jar goal.

    I found an "Improvement" (MJAR-199) in the maven-jar-plugin JIRA about this. Feel free to vote for it!