1

I'm trying to perform migration of my project from java 8 to java 11. What I did in root pom.xml:

  1. Replaced
<source>8</source>
<target>8</target>

With

<release>11</release>
  1. Configured maven-toolchain-plugin
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-toolchains-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>toolchain</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <toolchains>
                        <jdk>
                            <version>[11,12)</version>
                        </jdk>
                    </toolchains>
                </configuration>
            </plugin>

After that modules which don't use groovy compiled without problems. But few modules in this project use groovy.

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <compilerId>groovy-eclipse-compiler</compilerId>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-compiler</artifactId>
                        <version>3.6.0-03</version>
                    </dependency>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-batch</artifactId>
                        <version>3.0.3-01</version>
                    </dependency>
                </dependencies>
            </plugin>

I get following error:

[INFO] Using Groovy-Eclipse compiler to compile both Java and Groovy files
[DEBUG] Compiling 15 source files to D:\Projects\dxcore-java11\fix-markets\fix-server-tests\target\classes
[DEBUG] Command line options:
[DEBUG] -cp D:\Projects\dxcore-java11\fix-markets\target\classes;C:\Users\turbanov\.m2\repository\org\codehaus\groovy\groovy\3.0.3\groovy-3.0.3.jar;<a_lot_of_jars_here>; -d D:\Projects\dxcore-java11\fix-markets\target\classes -s D:\Projects\dxcore-java11\fix-markets\target\generated-sources\annotations -g -encoding UTF8 --release 11 -nowarn D:\Projects\dxcore-java11\fix-markets\src\client\TestClient.groovy
[INFO] Using Groovy-Eclipse compiler to compile both Java and Groovy files
[DEBUG] Compiling 15 source files to D:\Projects\dxcore-java11\fix-markets\fix-server-tests\target\classes
[INFO] Compiling in a forked process using C:\Users\turbanov\.m2\repository\org\codehaus\groovy\groovy-eclipse-batch\3.0.3-01\groovy-eclipse-batch-3.0.3-01.jar
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Failure executing groovy-eclipse compiler:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project fix-server-tests: Compilation failure
Failure executing groovy-eclipse compiler:
option --release is supported only when run with JDK 9 or above


    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:190)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:186)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:748)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure

What is wrong with my configuration? Does groovy-eclipse-compiler supports such configuration?

What is strange is that if I replace <release> back to use <source>11</source>/<target>8</target> all build fine.

cb4
  • 6,689
  • 7
  • 45
  • 57
turbanoff
  • 2,439
  • 6
  • 42
  • 99
  • Could you please clarify what "migration from Java 8 to Java 11" means for you? Do you want to use new features of Java language introduced after Java 8? Or you just want to run your existing Java 8 code-base with Java 11 runtime? – Illya Kysil Mar 12 '21 at 16:50
  • I want to use new language features and new API. I already checked that application works fine with java 11. All tests are passed. It's the final step in migration. – turbanoff Mar 12 '21 at 16:53
  • The release option is supported. But as stated you need to run maven with Java 9+ to use it. If you target Java 11 then I would run maven with Java 11. – emilles Mar 13 '21 at 00:10
  • But modules with java-only code are compiled fine. As I know `maven-toolchains-plugin` is what is actually for - to break hard dependency between JDK which run maven and JDK which used to actually compile the code. Usage of JDK 11 for maven build is a bit tricky for this project: we use TeamCity to build it and same Build Configuration is used to build all branches of the project. Even branches which are not migrated to java 11. And we can't adjust TeamCity configuration to use JDK 11 - it will break old branches. – turbanoff Mar 13 '21 at 12:20
  • Yes, I see now after some research that `groovy-eclipse-compiler` is not toolchain-aware. I have created this github issue to track the addition of this capability: https://github.com/groovy/groovy-eclipse/issues/1232 – emilles Mar 13 '21 at 19:52

2 Answers2

0

I'm trying to migration my project from java 8 to java 11.

I want to use new language features and new API.

The simplest solution for this migration would be to use Java 11 for Maven invocation. There is no need to use maven-toolchains-plugin in this case.

As for the errors reported by the groovy-eclipse-compiler - every example in the Release new version of Groovy Eclipse Maven plugin to support Java 11 issue is using maven-compiler-plugin with either explicit configuration like this:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>11</source>
        <target>11</target>
    </configuration>
</plugin>

or with implicit configuration like this:

<properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>

I suggest to follow these examples and drop <release> configuration completely.

Another suggestion would be to use maven-enforcer-plugin to enforce the minimum version of Java used for Maven invocation.

Illya Kysil
  • 1,642
  • 10
  • 18
  • As I know usage of `release` option is preferred over `source`/`target` pair. It was introduced to make sure that used JDK API matches actual JDK version. See https://stackoverflow.com/questions/60897480/what-is-release-element-on-configuration-for-the-maven-compiler-plugin – turbanoff Mar 16 '21 at 15:08
  • Given the new constraint provided in the comment - running Maven with Java 8 but compiling Java and Groovy code with Java 11 - my answer is not valid. But the constraint is still NOT part of the question. And yes, you need to run the compiler plugin which includes the repairs for the https://github.com/groovy/groovy-eclipse/issues/1232 . – Illya Kysil Mar 17 '21 at 12:04
0

As @emiles commented above:

Yes, I see now after some research that groovy-eclipse-compiler is not toolchain-aware. I have created this github issue to track the addition of this capability: github.com/groovy/groovy-eclipse/issues/1232

He put the fix in on 13 March into groovy-eclipse-compiler 3.7.0. I was having this selfsame issue on an AEM build, compiling groovy on an AEM Cloud Manager install that has both JDK8 and JDK11 installed, using the maven-toolchains-plugin to switch.

Upgrading to groovy-eclipse-compiler 3.7.0 and groovy-eclipse-batch 3.0.7-02 fixed the issue for me.

Tad
  • 141
  • 1
  • 4