Issue
Trying to run the following combination:
- Maven (3.6.1)
- OpenJDK 11
- With module-info.java
Fails with the following error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project tourconex: Fatal error compiling: Fa
iled to run the ecj compiler: Unrecognized option : --module-version -> [Help 1]
Have tried to add blank compilerArgs node, but without avail.
Removing module-info.java fixes the problem, but that's not what I want.
Also, looked at the source http://central.maven.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.8.1/
specifically at the source of CompilerMojo.java:
module-version is always added, so it seems there's no way to suppress it:
compilerArgs.add( "--module-version" );
compilerArgs.add( getProject().getVersion() );
Looking at the documentation of ecj, there's no "module-version" argument
So it seems that it just won't work at the moment!?
Maven Plugin section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerId>eclipse</compilerId>
<source>11</source>
<target>11</target>
<release>11</release>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.17.0</version>
</dependency>
</dependencies>
</plugin>
Solution
Until now ecj
does not support the option --module-version
.
It may have fallen through the cracks for several possible reasons:
- nobody cared, because the module version is not evaluated by JVM nor other tools
- perhaps it wasn't specified as a new compiler option before Java 9 GA (http://openjdk.java.net/jeps/261 does not have a version history, but I know that the text was changed significantly right on the release day).
Please file a feature request at https://bugs.eclipse.org/bugs/enter_bug.cgi?product=JDT
Edit: Your feature request has been implemented. While we missed today's release of Eclipse 2019-06, you may fetch ecj.jar from the next integration build below https://download.eclipse.org/eclipse/downloads/index.html - next full release is scheduled for September.
Edit2: After more research the simplest workaround might be to go back to version 3.8.0 of maven-compiler-plugin which does not try to pass --module-version
to the compiler. This happens only since 3.8.1 released this May.
Answered By - Stephan Herrmann
Answer Checked By - Robin (JavaFixing Admin)