[英]How do I pass -Xlint:deprecation or -Xlint:unchecked to Maven?
When I build my project I get errors like: 当我构建项目时,会出现类似以下错误:
[INFO] SomeClass.java: Some input files use or override a deprecated API.
[INFO] SomeClass.java: Recompile with -Xlint:deprecation for details.
[INFO] SomeClass.java: Some input files use unchecked or unsafe operations.
[INFO] SomeClass.java: Recompile with -Xlint:unchecked for details.
But when I put -Xlint:deprecation
or -Xlint:unchecked
in my MAVEN_OPTS
or .mvn/maven.config
I get: 但是,当我将
-Xlint:deprecation
或-Xlint:unchecked
放入我的MAVEN_OPTS
或.mvn/maven.config
我得到:
$ MAVEN_OPTS="-Xlint:unchecked " mvn -B clean test
Unrecognized option: -Xlint:unchecked
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
What gives? 是什么赋予了?
-Xlint
is a compiler option, not a maven option or jvm option. -Xlint
是编译器选项,不是maven选项或jvm选项。
On the command line maven accepts -Xlint
but it treats it as the -X
maven option ("debug") and ignores the rest. 在命令行上,maven接受
-Xlint
但会将其视为-X
maven选项(“调试”),而忽略其余部分。 So it doesn't have the expected effect. 因此它没有预期的效果。
In the specific case of these two compiler options you can set Maven properties that result in the desired compiler options being set. 在这两种编译器选项的特定情况下,您可以设置Maven属性,以设置所需的编译器选项。 Put these in your project's
.mvn/maven.config
, MAVEN_OPTS
env var, or on the command line: 将它们放在项目的
.mvn/maven.config
, MAVEN_OPTS
env var或命令行中:
-Dmaven.compiler.showWarnings=true
-Dmaven.compiler.showDeprecation=true
See maven compiler plugin . 参见maven编译器插件 。
You can also use the compilerArgs
property in your pom.xml
or a Maven settings.xml
user-defined profile. 您也可以使用
compilerArgs
财产在你pom.xml
或一个Maven settings.xml
用户自定义配置文件。 I don't see a way to set that List valued property as a system property. 我看不到将列表值属性设置为系统属性的方法。 You can't use
compilerArgument
or compilerArguments
either, they don't have user properties . 您也不能使用
compilerArgument
或compilerArguments
,因为它们没有用户属性 。
You may also find it useful to control the compiler's logging level; 您可能还会发现控制编译器的日志记录级别很有用。 for example, you can silence these warnings with:
例如,您可以使用以下方法使这些警告静音:
-Dorg.slf4j.simpleLogger.log.org.apache.maven.plugin.compiler.CompilerMojo=warn
Note that explicitly setting -Dmaven.compiler.showWarnings=false
will not suppress the -Xlint
messages. 请注意,显式设置
-Dmaven.compiler.showWarnings=false
不会抑制-Xlint
消息。 See How can I suppress javac warnings about deprecated api? 请参阅如何抑制关于不推荐使用的api的javac警告? .
。 Maven doesn't appear to offer a way to set the relevant properties
-Xlint:-deprecated -Xlint:-unchecked
on the command line. Maven似乎没有提供在命令行上设置相关属性
-Xlint:-deprecated -Xlint:-unchecked
的方法。 You can't set them directly settings.xml
either because you can't set individual plugin properties. 您也不能直接将它们
settings.xml
为settings.xml
,因为您无法设置单个插件属性。 It has to be the pom.xml
. 它必须是
pom.xml
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.