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

silver :

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?

df778899 :

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>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=36108&siteId=1