[
https://issues.apache.org/jira/browse/MJAR-232?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15389847#comment-15389847
]
Karl Heinz Marbaise commented on MJAR-232:
------------------------------------------
If I take your example project and run the build via {{mvn clean package}}:
{code}
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ sample ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ sample ---
[INFO] Building jar:
/Users/kama/ws-git-maven-bugs/test-jar-classifier/target/sample-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default) @ sample ---
[INFO] Building jar:
/Users/kama/ws-git-maven-bugs/test-jar-classifier/target/sample-1.0-SNAPSHOT-classes.jar
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:test-jar (default) @ sample ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar:
/Users/kama/ws-git-maven-bugs/test-jar-classifier/target/sample-1.0-SNAPSHOT-classes.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
{code}
As you can see {{maven-jar-plugin}} is executed in total three times which
shows that you pom file has some itches. Based on the life cycle
maven-jar-plugin is already bound to the life cycle which can be identified by
the line {{maven-jar-plugin:3.0.2:jar (default-jar)}} the other execution which
you can identify by {{maven-jar-plugin:3.0.2:jar (default)}} is the one you
have defined in your pom file.
So if you want to control which version of maven-jar-plugin will be used you
should only define a pluginManagement section in your pom like this:
{code:xml}
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
{code}
If you like to create an supplemental {{test-jar}} you should do it this way
(of course you should define the version of the plugin via pluginManagement
based on my given example):
{code:xml}
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
{code}
To get that correctly working you need to [follow the default folder structure
layout|https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html]
which you haven't done in your example.
So now let us take a look why you get the results you have.
First based on defining an execution within a {{pluginManagement}} results into
binding this execution to life cycle which is a [Bug in Maven which is already
fixed for Maven 3.4.0 |MNG-5368]. Apart from that you should never define
executions within a pluginManagement block.
Furthermore if I comment out the following:
{code:xml}
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>classes</classifier>
<includes>
<include>SampleMain.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
{code}
You will get the following result:
{code}
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ sample ---
[INFO] Building jar:
/Users/kama/ws-git-maven-bugs/test-jar-classifier/target/sample-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:test-jar (default) @ sample ---
[INFO] Building jar:
/Users/kama/ws-git-maven-bugs/test-jar-classifier/target/sample-1.0-SNAPSHOT-tests.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
{code}
which shows that the classifier you have defined in the execution will be used.
So now let us add back the previously commented out part..
This will result in inheriting the configuration from the part defined in the
pluginManagement based on the missing id in the executions which will result in
this:
{code}
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ sample ---
[INFO] Building jar:
/Users/kama/ws-git-maven-bugs/test-jar-classifier/target/sample-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default) @ sample ---
[INFO] Building jar:
/Users/kama/ws-git-maven-bugs/test-jar-classifier/target/sample-1.0-SNAPSHOT-classes.jar
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:test-jar (default) @ sample ---
[INFO] Building jar:
/Users/kama/ws-git-maven-bugs/test-jar-classifier/target/sample-1.0-SNAPSHOT-classes.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
{code}
> The MJP doesn't genereate artifact with 'tests' classifier for 'test-jar' goal
> ------------------------------------------------------------------------------
>
> Key: MJAR-232
> URL: https://issues.apache.org/jira/browse/MJAR-232
> Project: Maven JAR Plugin
> Issue Type: Bug
> Affects Versions: 3.0.0, 3.0.1, 3.0.2
> Environment: Windows 7
> Reporter: Eugene Maysyuk
> Labels: build, test
>
> The new version of maven-jar-plugin doesn't generate artifact with 'tests'
> classifier for 'test-jar' goal.
> I have prepared sample project on the github.
> https://github.com/EugenMaysyuk/test-jar-classifier
> You can build it with different maven-jar-plugin versions (2.6 and 3.0.0) to
> see the difference in 'test-jar' goal.
> The part of build log when I used the maven-jar-plugin:2.6:
> [INFO] --- maven-jar-plugin:*2.6:test-jar* (default) @ sample ---
> [WARNING] JAR will be empty - no content was marked for inclusion!
> [INFO] Building jar:
> D:\test-jar-classifier\target\sample-1.0-SNAPSHOT-*tests*.jar
> The part of build log when I used the maven-jar-plugin:3.0.2:
> [INFO] --- maven-jar-plugin:*3.0.2:test-jar* (default) @ sample ---
> [WARNING] JAR will be empty - no content was marked for inclusion!
> [INFO] Building jar:
> D:\test-jar-classifier\target\sample-1.0-SNAPSHOT-*classes*.jar
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)