This is (according to me) the cleanest solution
for projects that don't contain production code but do contain tests:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<skipIfEmpty>true</skipIfEmpty>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
It indicates what you want:
- to skip trying to package "no production code" into a jar
- don't try to install/deploy the non-existing jar
leaving test execution untouched.
Like @John Camerin mentioned it is NOT advised to use <packaging>pom</packaging>
unless the ONLY thing your pom should do is gather dependencies.
Otherwise, if you have tests, they would be skipped without warning, which is not what you want.
A shorter alternative
Some of these configuration parameters are tied to user properties:
maven-jar-plugin
's skipIfEmpty
parameter sadly is not linked to any user property
maven-install-plugin
's skip
parameter gets its value from maven.install.skip
maven-deploy-plugin
's skip
parameter gets its value from maven.deploy.skip
This means the pom could be shortened to
<properties>
<maven.install.skip>true</maven.install.skip>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<skipIfEmpty>true</skipIfEmpty>
</configuration>
</plugin>
</plugins>
</build>