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

14.6k views Asked by At

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>
4

There are 4 answers

3
Stefan On BEST ANSWER

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#

0
gleitonfranco On

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

0
lubrum On

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.

0
Gitesh kumar Jha On

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.