Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - Suppress [WARNING] JAR will be empty - no content was marked for inclusion in pom.xml

Tags:

java

junit

maven

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?

like image 457
silver Avatar asked Jul 28 '18 10:07

silver


People also ask

How to exclude jar files in 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.

How to exclude files in maven?

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.

How to exclude plugin in maven?

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.


1 Answers

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>
like image 138
df778899 Avatar answered Sep 20 '22 11:09

df778899