2

I am using the maven compiler plugin 3.0 and I get the error "Element compilerArgs is not allowed here". This seems to work for command line but I get this Error in the IDE,.I use IDEA 2017.2 community edition. There is likely some schema missing somewhere, but I am not sure. Does anyone have a good way to solve issues like this, that is not to send a bug report to JetBrains and wait for a fix?

<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>
patrik
  • 4,506
  • 6
  • 24
  • 48
  • by removing the compilerArgs? – Stultuske Nov 17 '17 at 08:13
  • @Stultuske This is not a good solution. You see, I need this attribute and it is supported by maven compiler plugin 3.0. `mvn clean compile` takes it. Intellj does not. – patrik Nov 17 '17 at 08:15
  • whether it's a good solution or not, your error message is saying that either you've used a tag you're not allowed to use, or you've used it in the wrong place. leaving it there won't solve the issue neither – Stultuske Nov 17 '17 at 08:17
  • ok, and are you sure that's the version your intellij instance uses? – Stultuske Nov 17 '17 at 08:18
  • No, I am not, but I am am not really sure how intellij and maven integrates. – patrik Nov 17 '17 at 08:19
  • you can tell intellij to use your local maven setup, instead of the embedded one – Stultuske Nov 17 '17 at 08:20
  • @Stultuske seems you was right all along xD. There were some versioning issues. Thank you anyway. – patrik Nov 24 '17 at 08:16

4 Answers4

6

I suggest you try maven-compiler-plugin version 3.7.0.

If you stay on version 3.0, update your setup so it looks like this example: http://maven.apache.org/plugins-archives/maven-compiler-plugin-3.0/examples/pass-compiler-arguments.html

If you can go up to 3.7.0, take a look at this example (which is very similar to your code): https://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html#

Stefan
  • 2,395
  • 4
  • 15
  • 32
  • Great, this works! So I assume the compilerArg have never worked. Weird that maven have just swallowed that before. Anyway, thanks! – patrik Nov 17 '17 at 08:22
  • Which one works? version 3.7.0 (this would be my guess)? Or modifying the setup for 3.0? And feel free to mark the question as Accepted. – Stefan Nov 17 '17 at 08:24
  • 1
    Both options work. Anyway, apparently I have to wait a few minutes before I can accept the answer. Also +1 for coming up with a solution, which is so easy that I start feeling stupid :). – patrik Nov 17 '17 at 08:28
0

Changing the tag name to compilerArguments or another allowed by the IDE may work.

gleitonfranco
  • 791
  • 6
  • 9
0

I was with almost the same problem.

I was with jdk 16, maven compiler 3.8.1 and IntelliJ version 2021.1.3.

After any changes in pom.xml, a small icon on the right showed to me (Load Maven Changes). After clicking that button, the issue was solved.

lubrum
  • 352
  • 4
  • 21
0

This is how I solved it without making any changes into the pom.xml

mvn clean compile -Dmaven.compiler.forceJavacCompilerUse=true

This will highlight the actual compilation error in the console to solve.