Maven - How do I create source jar for test package?

I am able to generate sources for test with help of below plugin. can you post your pom file ?

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>test-jar</goal>
            </goals>
        </execution>
    </executions>
 </plugin>

To generate both standard source and test source JARs, use the following plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>test-jar</goal>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Note that this will not generate a test JAR (only a standard JAR). To generate both a standard and test JAR, you can use the following plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>test-jar</goal>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I would suggest looking at the plugin doco for that goal

https://maven.apache.org/plugins/maven-source-plugin/test-jar-mojo.html

It looks like the test-jar goal uses the default manifest file, which would explain why the sources are combined into the same jar file.

My suggestion is to use the defaultManifestFile setting to point to a new manifest file. You will need to define this file yourself, but then you can ensure that the target jar is given a distinct name, thus making it a different JAR file.

Hope this helps

Tags:

Java

Maven