0

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

https://help.eclipse.org/oxygen/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-using_batch_compiler.htm

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>
Mebin Joe
  • 2,172
  • 4
  • 16
  • 22
jpmsnewbie
  • 115
  • 7

2 Answers2

0

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.

Stephan Herrmann
  • 7,963
  • 2
  • 27
  • 38
  • that was what I also thought - probably the combination of maven + ecj + java modules is not that very common and the few people that try that out don't bother much if it doesn't work. I will open feature request as suggested an cross reference the posts – jpmsnewbie Jun 11 '19 at 13:38
  • The combination maven + ecj + JPMS is not so uncommon, but adding `--module-version` to the mix seems to be infrequent. – Stephan Herrmann Jun 14 '19 at 21:57
  • Well, that's what maven-compiler-plugin (at least in latest version) does by default, so maven/ecj/jpms simply doesn't work in my opinion – jpmsnewbie Jun 16 '19 at 08:25
  • Do you have a reference where the maven-compiler-plugin team announced / documented what module-related options they pass? It seems not even the m2e team got any notice about this. – Stephan Herrmann Jun 17 '19 at 20:02
  • Here's the commit from August 2018: https://github.com/apache/maven-compiler-plugin/commit/2ba3f260c524c226dfd0e94fb22ab2b007519bb1 – jpmsnewbie Jun 19 '19 at 05:35
  • This is the jira issue for the change: https://issues.apache.org/jira/plugins/servlet/mobile#issue/MCOMPILER-322 – jpmsnewbie Jun 19 '19 at 05:39
  • Probably in 3.8.0 (end if august 2018) but issue is not mentioned in release notes: https://blogs.apache.org/maven/entry/apache-maven-compiler-plugin-version – jpmsnewbie Jun 19 '19 at 05:43
  • @jpmsnewbie thanks for the links, but the 3.8.0 release notes are older than the fix :) It's actually mentioned in the 3.8.1 notes: https://blogs.apache.org/maven/entry/apache-maven-compiler-plugin-version1 (boy, how are people supposed to find those release notes within that unstructured stream of announcements?). – Stephan Herrmann Jun 19 '19 at 21:01
  • Right; I was looking st 3.8.0 instead of 3.8.1 – jpmsnewbie Jun 20 '19 at 15:16
  • Stephen, maybe you can advise me on a follow up question? I see that the fix is targeted to be part of Eclipse 4.13 (2019-09). What would be the simplest way to make my mvn environment use ecj with the fix? Is there a maven repository with 4.13 snapshot for ecj artifact for example? – jpmsnewbie Jun 20 '19 at 15:18
  • @jpmsnewbie unfortunately publishing snapshots to maven is still blocked by technical issues converting osgi artifacts to maven. Perhaps you want to manually deploy it to your local maven repo. As mentioned you can get it from https://download.eclipse.org/eclipse/downloads/drops4/I20190620-0130/download.php?dropFile=ecj-I20190620-0130.jar – Stephan Herrmann Jun 20 '19 at 17:58
  • replaced ecj-3.17.0.jar in my local .m2 repository with the file you have linked, now I'm getting error on mvn compile: – jpmsnewbie Jun 21 '19 at 15:54
  • [DEBUG] java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.resolveAnnotations(AnnotationDiscoveryVisitor.java:255) at org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.visit(AnnotationDiscoveryVisitor.java:225) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1425) at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:812) ... – jpmsnewbie Jun 21 '19 at 15:55
  • @jpmsnewbie do you need annotation processing? Otherwise please try adding `-proc:none` to the command line. – Stephan Herrmann Jun 21 '19 at 18:24
  • it's weird; I had to re-create my local git clone for reasons unrelated to ecj and now patched ecj works! So that's settled and should I encounter issues with ecj again, I'll create new thread. Stephen - thanks for your help! – jpmsnewbie Jun 22 '19 at 14:26
0

Opened issue / feature request on eclipse.org: https://bugs.eclipse.org/bugs/show_bug.cgi?id=548195

jpmsnewbie
  • 115
  • 7