[英]How to compile using -Xlint:unchecked in a Maven project?
In NetBeans 7.2, I'm having trouble finding how to compile using -Xlint:unchecked in a Maven project.在 NetBeans 7.2 中,我无法找到如何在 Maven 项目中使用 -Xlint:unchecked 进行编译。 Under an Ant project, you can change compiler flags by going to Project Properties -> Compiling, but Maven projects don't seem to have any such option.
在 Ant 项目下,您可以通过转到项目属性 -> 编译来更改编译器标志,但 Maven 项目似乎没有任何此类选项。
Is there any way to configure the IDE to compile with such flags using Maven?有没有办法配置 IDE 以使用 Maven 使用此类标志进行编译?
I guess you can set compiler arguments in your pom.xml.我猜您可以在 pom.xml 中设置编译器参数。 Please refer this http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html
请参考这个http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html
<compilerArgument>-Xlint:unchecked</compilerArgument>
I want to elaborate on @Nishant's answer.我想详细说明@Nishant 的回答。 The
compilerArgument
tag needs to go inside plugin/configuration
tag. compilerArgument
标签需要进入plugin/configuration
标签。 Here is a full example:这是一个完整的例子:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<testSource>1.8</testSource>
<testTarget>1.8</testTarget>
<compilerArgument>-Xlint:unchecked</compilerArgument>
</configuration>
</plugin>
</plugins>
This works for me...这对我有用...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
<compilerArgs>
<arg>-Xlint:unchecked</arg> <-------this right here ---->
</compilerArgs>
</configuration>
</plugin>
</plugins>
The pom file information is spot on. pom 文件信息是正确的。 I had the additional challenge of building someone else's Maven project in Jenkins and not having access to the pom file repository.
我还面临在 Jenkins 中构建其他人的 Maven 项目而无法访问 pom 文件存储库的额外挑战。
I created a pre-build step to insert the compiler parameter into the pom file after downloading it from git, for example例如,我创建了一个预构建步骤,在从 git 下载后将编译器参数插入到 pom 文件中
sed -i 's|/target> *$|/target>\n<compilerArgument>\n-Xlint:deprecation\n</compilerArgument>|' $WORKSPACE/pom.xml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.