0

I'm using Maven in Eclipse for a modular Java project, and have managed to make Maven use the Eclipse compiler following the answer to this question.

However, the Maven test-compile target fails with the error message

Failed to run the ecj compiler: Unrecognized option : --patch-module

which is quite surprising (actually unbelievable) because Eclipse is well up to patching modules.

Here's the pom.xml for a MVE, consisting of a modular project patchmodule:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>patchmodule</groupId>
    <artifactId>patchmodule</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <compilerId>eclipse</compilerId>
                    <release>16</release>
                    <compilerArguments>
                        <properties>${project.basedir}/.settings/org.eclipse.jdt.core.prefs</properties>
                    </compilerArguments>
                </configuration>

                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.plexus</groupId>
                        <artifactId>plexus-compiler-eclipse</artifactId>
                        <version>2.12.1</version>
                    </dependency>

                    <dependency>
                        <groupId>org.eclipse.jdt</groupId>
                        <artifactId>ecj</artifactId>
                        <version>3.31.0</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

The error kicks in as soon as you give the project a single test, such as

package patchmodule.test;

import static org.junit.jupiter.api.Assertions.*;

class Test {
    @org.junit.jupiter.api.Test
    void test() {
        fail("Not yet implemented");
    }
}

and then do a Maven install, or any target that will invoke testCompile.

Is this a bug (and if so, whose)? More importantly, is there a way to work around it? Any help is much appreciated.

Arend
  • 2,363
  • 1
  • 18
  • 18
  • 1
    ecj doesn't use exactly the same command line arguments as javac. I don't see `--patch-module` in the list [here](https://help.eclipse.org/2022-09/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-using_batch_compiler.htm&resultof%3D%2522%2565%2563%256a%2522%2520) – greg-449 Oct 26 '22 at 13:54
  • @greg-449 Nevertheless, when inspecting the Dependencies tab of an Eclipse JUnit run configuration, under "Override Dependencies" a --patch-module option is specified – Arend Oct 26 '22 at 14:52
  • @greg-449 Wait, the option I referred to in the comment above is for the JVM, not the compiler. OK then, if ecj doesn't have `--patch-module`, how does it manage to compile my test classes in the first place? – Arend Oct 26 '22 at 14:55

0 Answers0