My maven project intentionally only needs src/test/java
and src/test/resources
. After removing src/main/*
folders, the expected warning showed up upon mvn verify
:
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: D:\dev\java\my-project\target\my-project-0.0.1-SNAPSHOT.jar
How to suppress this warning apart from having a class with an empty main()
method in src/main/java
?
EDIT:
As -q
suppresses the warning, a followup would be if this can be done programmatically in the pom.xml
?
How to include/exclude content from jar artifact. Specify a list of fileset patterns to be included or excluded by adding <includes> / <include> or <excludes> / <exclude> in your pom. xml . Note that the patterns need to be relative to the path specified for the plugin's classesDirectory parameter.
Thus, we may have to specify only the files that we want to include or specify the files that we want to exclude. To include a resource, we only need to add an <includes> element. And to exclude a resource, we only need to add an <excludes> element.
We can use the skip parameter to disable the plugin. If we take a look at the documentation for the maven-enforcer-plugin, we can see that it has a skip parameter that we can implement. Support for the skip parameter should be the first thing we check because it is the simplest solution and the most conventional.
The warning is actually based on whether it can find the configured <classesDirectory>
- by default target\classes
.
This means one simple way to bypass the warning is to point it at another deliberately empty directory:
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>dummy</classesDirectory>
</configuration>
</plugin>
</plugins>
</build>
Alternatively, to avoid the need for the empty directory, exclude everything from another directory:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>src</classesDirectory>
<excludes>
<exclude>**</exclude>
</excludes>
</configuration>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With