【发布时间】:2013-09-06 09:04:49
【问题描述】:
有没有办法通过命令行将编译器参数传递给 Maven?我知道我可以在 compiler-plugin 中指定它,但我也想从命令行运行 Xlint。所以我尝试了类似
mvn clean install -DskipTests=true -DcompilerArgument=-Xlint:deprecation
但没有成功。
【问题讨论】:
标签: java maven compilation
有没有办法通过命令行将编译器参数传递给 Maven?我知道我可以在 compiler-plugin 中指定它,但我也想从命令行运行 Xlint。所以我尝试了类似
mvn clean install -DskipTests=true -DcompilerArgument=-Xlint:deprecation
但没有成功。
【问题讨论】:
标签: java maven compilation
对于这个具体案例(弃用警告),实际上是一个property which can be used from the command line:
mvn clean install -Dmaven.compiler.showDeprecation=true
与 compilerArgument 解决方案相反,这也适用于在 maven 进程中使用编译器,而不仅仅是在使用 fork=true 时。
一个类似有用的属性是maven.compiler.showWarnings。
【讨论】:
-Dmaven.compiler.showDeprecation(没有=true)也可以:)
你可以像这样定义一个编译器插件:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>${compilerArgument}</compilerArgument>
</configuration>
</plugin>
然后从命令行传递参数:
mvn -DcompilerArgument=-Xlint:deprecation compile
如果你不传递-DcompilerArgument,它不会破坏构建,因为编译器插件参数中的'compilerArgument'将为空并被忽略。
【讨论】:
pom.xml 完好无损。但是很好的解决方法,谢谢
compile:compile parameters 都没有默认用户属性。