如何使用Xlint编译Maven项目

时间:2013-09-06 09:04:50

标签: java maven compilation

有没有办法如何通过命令行将编译器参数传递给Maven?我知道我可以在compiler-plugin中指定,但我也希望从命令行运行Xlint。所以我试过像

这样的东西
mvn clean install -DskipTests=true -DcompilerArgument=-Xlint:deprecation

但没有成功。

2 个答案:

答案 0 :(得分:25)

对于这个具体案例(弃用警告),实际上 property which can be used from the command line

mvn clean install -Dmaven.compiler.showDeprecation=true

与compilerArgument解决方案相反,这在maven进程中使用编译器时也有效,不仅在使用fork = true时。

同样有用的属性是maven.compiler.showWarnings

答案 1 :(得分:19)

您可以像这样定义编译器插件:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgument>${compilerArgument}</compilerArgument>
    </configuration>
</plugin>

然后从命令行传递参数:

mvn -DcompilerArgument=-Xlint:deprecation compile

如果你没有传递-DcompilerArgument,它将不会破坏构建,因为编译器插件参数中的'compilerArgument'将为空并被忽略。

相关问题