如何解决Element compilerArgs is not allowed here Error in maven compiler plugin?

How to solve Element compilerArgs is not allowed here Error in maven compiler plugin?

我正在使用 maven 编译器插件 3.0,但出现错误 "Element compilerArgs is not allowed here"。这似乎适用于命令行,但我在 IDE 中收到此错误。我使用 IDEA 2017.2 社区版。某处可能缺少某些架构,但我不确定。有没有人有解决此类问题的好方法,即不向 JetBrains 发送错误报告并等待修复?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.0</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
        <fork>true</fork>
        <compilerArgs>
            <arg>-DspecificArg</arg>
        </compilerArgs>
    </configuration>
</plugin>

我建议你试试 maven-compiler-plugin 版本 3.7.0.

如果您继续使用 3.0 版,请更新您的设置,使其看起来像这个示例:http://maven.apache.org/plugins-archives/maven-compiler-plugin-3.0/examples/pass-compiler-arguments.html

如果你能升级到3.7.0,看看这个例子(和你的代码很相似): https://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html#

将标签名称更改为 compilerArguments 或 IDE 允许的其他名称可能有效。

我遇到了几乎同样的问题。

我用的是 jdk 16,maven 编译器 3.8.1 和 IntelliJ 版本 2021.1.3。

在 pom.xml 中进行任何更改后,右侧会显示一个小图标(加载 Maven 更改)。点击那个按钮后,问题就解决了。

这就是我在不对 pom.xml

进行任何更改的情况下解决问题的方法
mvn clean compile -Dmaven.compiler.forceJavacCompilerUse=true

这将在控制台中突出显示要解决的实际编译错误。