Had a requirement to make a separate project with only test cases. The project (built using Maven) doesn't contain any files in the source package; it just contains test cases in the test sources. Currently, packaging them into a test JAR using maven-jar-plugin
; relevant code as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${assembleDir}/lib</outputDirectory>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.json</exclude>
</excludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.companyname.project.TestRunner</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Class-Path>../conf/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
When I build the project, an empty JAR file for the source package also gets created. How can I avoid this without stopping the packaging of the test JAR?
A desirable solution would be to prevent Maven from creating JAR for source package if it contains no files.
The Solution
As per this answer to the above redirected question, added
<execution>
<id>default-jar</id>
<phase/>
</execution>
to the <executions>
section above.
Although, not the exact solution that I wanted but it works never the less.