Maven-禁止显示[警告] JAR将为空-pom.xml中未标记任何要包含的内容 [英] Maven - Suppress [WARNING] JAR will be empty - no content was marked for inclusion in pom.xml
问题描述
我的maven项目故意仅需要src/test/java
和src/test/resources
.删除src/main/*
文件夹后,mvn verify
上将出现预期的警告:
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
除了在src/main/java
中使用空的main()
方法的类之外,如何抑制此警告?
How to suppress this warning apart from having a class with an empty main()
method in src/main/java
?
当-q
禁止显示警告时,是否可以在pom.xml
中以编程方式完成此操作?
As -q
suppresses the warning, a followup would be if this can be done programmatically in the pom.xml
?
推荐答案
警告实际上是基于是否可以找到配置的<classesDirectory>
-默认为target\classes
.
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>
这篇关于Maven-禁止显示[警告] JAR将为空-pom.xml中未标记任何要包含的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!