Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Maven项目中使用-Xlint:unchecked进行编译?_Java_Maven_Netbeans - Fatal编程技术网

Java 如何在Maven项目中使用-Xlint:unchecked进行编译?

Java 如何在Maven项目中使用-Xlint:unchecked进行编译?,java,maven,netbeans,Java,Maven,Netbeans,在NetBeans7.2中,我很难找到如何在Maven项目中使用-Xlint:unchecked进行编译。在Ant项目下,您可以通过转到项目属性->编译来更改编译器标志,但是Maven项目似乎没有任何这样的选项 有没有办法使用Maven将IDE配置为使用此类标志进行编译?我想您可以在pom.xml中设置编译器参数。请参考这个 -Xlint:未选中 我想详细说明@Nishant的答案。compilerArgument标签需要放入plugin/configuration标签中。以下是一个完整的示例:

在NetBeans7.2中,我很难找到如何在Maven项目中使用-Xlint:unchecked进行编译。在Ant项目下,您可以通过转到项目属性->编译来更改编译器标志,但是Maven项目似乎没有任何这样的选项


有没有办法使用Maven将IDE配置为使用此类标志进行编译?

我想您可以在pom.xml中设置编译器参数。请参考这个

-Xlint:未选中

我想详细说明@Nishant的答案。
compilerArgument
标签需要放入
plugin/configuration
标签中。以下是一个完整的示例:

<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>

org.apache.maven.plugins
maven编译器插件
3.3
1.8
1.8
1.8
1.8
-Xlint:未选中

pom文件信息当场显示。我还有一个额外的挑战,就是在Jenkins中构建其他人的Maven项目,而不能访问pom文件存储库

例如,我创建了一个预构建步骤,在从git下载pom文件后将编译器参数插入到pom文件中

sed -i 's|/target> *$|/target>\n<compilerArgument>\n-Xlint:deprecation\n</compilerArgument>|' $WORKSPACE/pom.xml
sed-i的|/target>*$|/target>\n\n-Xlint:deprecation\n |'$WORKSPACE/pom.xml
这对我很有用

<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>

org.apache.maven.plugins
maven编译器插件
3.8.1
11
11
${annowed.dir}
-Xlint:未选中

我创建了一个小测试程序,它应该会生成一个关于静态方法使用的警告,但我似乎无法让maven生成任何关于它的警告。这里发布了示例程序和pom文件的Gist->@RonDahlgren:为什么您希望这会引发警告?@haylem-访问静态字段或方法时,应该会生成一个启用了该选项的警告。这是javac使用的详细信息,但它很常见:@RonDahlgren:对,这是一个常见的警告,但javac没有报告过。Eclipse编译器和其他一些编译器以及许多其他代码样式检查器都报告了它,但javac不会报告它。如果愿意的话,可以让maven使用eclipse编译器。链接的页面建议条目应该放在组中。这似乎合乎逻辑。根据下面的链接,它实际上在组中。如果需要传递多个参数,可能会收到
错误。参见此答案,了解备选方案
,给出所需的上下文参数是有用答案的重要组成部分。非常感谢。糟糕的解决方案。完成这个项目。并向他们发送一个包含更改的拉取请求。
<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>