IntelliJ Compiles Modules Perfectly But Maven Compile Task Fails

Viewed 93

I have a Maven project with 17 modules that I'm editing using IntelliJ 2020.2. It uses the bundled Maven version 3.6.3.

If I ask IntelliJ to run Junit tests in each module they compile and pass without a problem.

But when I run the compile, install, or deploy Maven lifecycle task in the root pom the modules fail to compile:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project qq-dtc-properties: Fatal error compiling

If I add debug flags and re-run the Maven task I don't see any errors or new information.

Why would IntelliJ successfully build and run test cases but Maven fail?

Here's the really weird part.

If I run the root compile task it fails once, twice, but succeeds on the third try. I had to repeat that for each module. It's like a partridge in a pear tree: I build that first module 3*17 = 51 times.

I'm mystified about Maven't behavior. Has anyone else seen something like this?

1 Answers

I found my answer.

When I used the maven.compiler.source and maven.compiler.target default variable names I had a problem.

All was well after replacing them with custom variable names common-modules.compiler.source and common-modules.compiler.target, set in <properties> in the bill of materials pom:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <parameters>true</parameters>
                <source>${common-modules.compiler.source}</source>
                <target>${common-modules.compiler.target}</target>
                <release>${common-modules.compiler.release}</release>
            </configuration>
        </plugin>
Related