【问题标题】:IntelliJ IDE error java: warnings found and -Werror specifiedIntelliJ IDE错误java:发现警告并指定-Werror
【发布时间】:2023-04-09 18:10:01
【问题描述】:

当我尝试构建/运行项目时,我的 java 项目中的 IDE (2020.3.4) 出现以下错误。由于这个问题,我无法通过 IDE 构建/运行应用程序。

java: warnings found and -Werror specified

我在我的 POM 文件中找到了下面的行,并尝试对此进行评论。但同样的错误。

                    <configuration>
                        <forceJavacCompilerUse>true</forceJavacCompilerUse>
                        <compilerArgs>
<!--                            <arg>-Werror</arg>-->
                            <arg>-verbose</arg>
                        </compilerArgs>
                        <source>11</source>
                        <target>11</target>  <!--or <release>10</release>-->
                    </configuration>

这是任何设置特定的错误。

【问题讨论】:

    标签: intellij-idea maven-3


    【解决方案1】:

    我在我的 POM 文件中找到了以下行,并尝试对此进行评论。但同样的错误。

    确保您已从 pom.xml 文件中所有可能的位置删除此标志,并在 Maven 工具窗口中调用 Reload 操作。

    【讨论】:

    • "invalidate Caches /Restart" 成功了。我以前试过这个。但不确定它是如何突然修复的。
    【解决方案2】:

    我遇到了同样的问题,我通过从 Intellij 中删除 Werror 标志解决了这个问题:

    file > settings > Build, Execution Deployment > Java Compiler
    

    在底部,您可以在Override compiler parameter 下找到它,您可以通过单击- 按钮删除该选项

    另外,验证您是否将此标志传递给maven-compiler-plugin,如果不需要,请将其删除。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <compilerArgs>
                    <arg>-Werror</arg>
                    <arg>-Xlint:all</arg>
                    <arg>-Xlint:-deprecation</arg>
                    <arg>-Xlint:-options</arg>
                    <arg>-Xlint:-processing</arg>
                    <arg>-Xlint:-serial</arg>
                </compilerArgs>
                <showWarnings>true</showWarnings>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
    

    【讨论】:

    • 我在 IntelliJ 中的 Java Compiler - Override compiler parameter 下没有看到它,仅列出了那里的模块。
    【解决方案3】:

    我正在搜索-Werror,但没有返回任何结果。 在 maven-compiler-plugin 中可以不使用 - 作为标记,例如:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <compilerArguments combine.children="append">
                <Werror />
            </compilerArguments>
        </configuration>
    </plugin>
    

    注释掉这篇文章很有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-19
      • 1970-01-01
      • 2014-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多