Search code examples
javamavenjunit

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


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?


Solution

  • 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>