【问题标题】:How to solve Element compilerArgs is not allowed here Error in maven compiler plugin?如何解决 Element compilerArgs is not allowed here Maven 编译器插件中的错误?
【发布时间】:2018-04-30 23:00:02
【问题描述】:

我正在使用 maven 编译器插件 3.0,我收到错误“此处不允许使用元素 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>

【问题讨论】:

  • 通过删除 compilerArgs?
  • @Stultuske 这不是一个好的解决方案。你看,我需要这个属性,它被 maven 编译器插件 3.0 支持。 mvn clean compile 接受。 Intellj 没有。
  • 无论它是否是一个好的解决方案,您的错误消息都是说您使用了不允许使用的标签,或者您在错误的地方使用了它。放在那里也解决不了问题
  • 好的,您确定这是您的 intellij 实例使用的版本吗?
  • 不,我不是,但我不确定 intellij 和 maven 是如何集成的。

标签: java maven-compiler-plugin intellij-idea2017


【解决方案1】:

我建议你尝试 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#

【讨论】:

  • 太好了,这行得通!所以我假设 compilerArg 从来没有工作过。奇怪的是,maven 之前刚刚吞下了它。无论如何,谢谢!
  • 哪一个有效? 3.7.0 版(这是我的猜测)?或者修改 3.0 的设置?并随时将问题标记为已接受。
  • 这两个选项都有效。无论如何,显然我必须等待几分钟才能接受答案。还 +1 用于提出解决方案,这很容易,我开始感到愚蠢:)。
【解决方案2】:

将标签名称更改为 compilerArguments 或 IDE 允许的其他名称可能会起作用。

【讨论】:

    【解决方案3】:

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

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

    对 pom.xml 进行任何更改后,右侧会出现一个小图标(Load Maven Changes)。点击那个按钮后,问题就解决了。

    【讨论】:

      【解决方案4】:

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

      mvn clean compile -Dmaven.compiler.forceJavacCompilerUse=true
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-19
        • 2019-09-18
        • 1970-01-01
        • 2022-10-15
        • 2016-06-23
        • 2019-06-09
        • 2019-07-03
        • 2021-04-11
        相关资源
        最近更新 更多