繁体   English   中英

如何解决 Element compilerArgs is not allowed here Maven 编译器插件中的错误?

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

我正在使用 maven 编译器插件 3.0,我收到错误“此处不允许使用 Element compilerArgs”。 这似乎适用于命令行,但我在 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 中进行任何更改后,右侧会显示一个小图标( Load Maven Changes )。 单击该按钮后,问题就解决了。

这就是我在不对 pom.xml 进行任何更改的情况下解决它的方法

mvn clean compile -Dmaven.compiler.forceJavacCompilerUse=true

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM