Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f22dead

Browse files
committed
Maven Toolchains now work with a new Maven Compiler Plugin version. Updated the documentation and added an example configuration for Java16.
1 parent 7e81783 commit f22dead

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,6 @@ docker build -t javaupgrades -f ..\DockerfileJava8 --build-arg DISABLE_CACHE="%d
517517
518518
519519
## Maven Toolchains
520-
**Please read until the end, for now I don't recommend the Maven toolchains as there appears to be a bug.**
521-
522520
Maven Toolchains can be used to configure the JDK's present on your machine and then select one to use in the `pom.xml` of the project.
523521
524522
First create a `toolchains.xml` located in *${user.home}/.m2/*
@@ -566,7 +564,6 @@ First create a `toolchains.xml` located in *${user.home}/.m2/*
566564
```
567565
568566
Then in the `pom.xml` configure which JDK from the toolchains.xml you want to use:
569-
570567
```xml
571568
<build>
572569
<plugins>
@@ -593,18 +590,18 @@ Then in the `pom.xml` configure which JDK from the toolchains.xml you want to us
593590
</build>
594591
```
595592
596-
Unfortunately currently there seems to be a bug as building the project with the toolchain gives:
593+
Make sure to update the Maven Compiler Plugin. When using an older version, combined with the Toolchains Plugin, the errors are not really detailed:
597594
```shell script
598595
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project broken: Compilation failure -> [Help 1]
599596
```
600597
601-
While compiling without the toolchain gives the more descriptive error message:
598+
When using a newer version of the Maven Compiler Plugin the error message provides more detailed information:
602599
```shell script
603-
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project broken: Fatal error compiling: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x21bd20ee) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @0x21bd20ee -> [Help 1]
600+
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project lombok_broken: Compilation failure
601+
[ERROR] java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @...) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironme
602+
nt (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @...
604603
```
605604
606-
So I don't recommend the usage of Maven Toolchains for upgrading to Java 16 or 17 at this point in time.
607-
608605
# Interesting other things
609606
610607
## Multi release JAR

java16/pom.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<plugin>
2323
<groupId>org.apache.maven.plugins</groupId>
2424
<artifactId>maven-compiler-plugin</artifactId>
25-
<version>3.8.1</version>
25+
<version>3.10.1</version>
2626
<configuration>
2727
<release>${maven.compiler.release}</release>
2828
</configuration>
@@ -32,6 +32,26 @@
3232
<artifactId>maven-dependency-plugin</artifactId>
3333
<version>3.1.2</version>
3434
</plugin>
35+
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-toolchains-plugin</artifactId>
39+
<version>3.0.0</version>
40+
<configuration>
41+
<toolchains>
42+
<jdk>
43+
<version>17</version> <!--${maven.compiler.release}</version>-->
44+
</jdk>
45+
</toolchains>
46+
</configuration>
47+
<executions>
48+
<execution>
49+
<goals>
50+
<goal>toolchain</goal>
51+
</goals>
52+
</execution>
53+
</executions>
54+
</plugin>
3555
</plugins>
3656
</build>
3757
</project>

0 commit comments

Comments
 (0)