Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.code.TypeTags when using lombok
MavenJava 8Maven PluginLombokMaven Problem Overview
I have following dependency in pom.xml:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.8</version>
</dependency>
When I run mvn clean install
, I have following error:
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.code.TypeTags
at java.lang.ClassLoader.findClass (ClassLoader.java:711)
at java.lang.ClassLoader.loadClass (ClassLoader.java:566)
at lombok.launch.ShadowClassLoader.loadClass (ShadowClassLoader.java:418)
I tried to use java 1.8, 1.9, 1.10
. And I tried lombok 1.6.10, 1.6.12, 1.6.20
. All of them have the same problem.
Maven Solutions
Solution 1 - Maven
I am able to solve the problem in my maven project with Java-10 and Lombok 1.18.2.
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
<scope>provided</scope>
</dependency>
Solution 2 - Maven
I had changed the lombok
version and it worked for me.
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.22</version>
<scope>provided</scope>
</dependency>
Solution 3 - Maven
I have the same problem and I solve it by adding this code in pom.xml
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.18.0.0</version>
</dependency>
Solution 4 - Maven
Solved the issue by upgrading lombok version from 1.16.18 to 1.16.22 . I suspect any compatible version higher than .22 might do the trick.
Solution 5 - Maven
my project uses java1.8,and this problem have be solved by using lombok 1.18.4.
Solution 6 - Maven
Solved this by:
-
download the lombok-edge.jar,
-
using following dependency:
org.projectlombok lombok 1.16.21 system /Users/xxx/Downloads/lombok-edge.jar
Solution 7 - Maven
This happened with me when I installed maven
with brew which also installed Java.15.x that leads to this error.
To validate, add debug option -X
while building with maven and check the Java version that maven is using.
Delete the Java.15x directory and set JAVA_HOME in your .bashrc
with the correct version of Java.
Solution 8 - Maven
I always managed to resolve this issue with numerous old projects using older version of Lombok by simply upgrading the Lombok version
With this upgrade of Lombok; for projects with heavy memory during test running phases I have also had to start specifying memory configurations for maven-surefire-plugin
which generally seems to now need more memory to avoid Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
errors
See below for example working pom.xml configs
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
</properties>
...
<lombok.version>1.18.2</lombok.version>
...
</properties>
<dependencies>
...
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
...
</dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!--Extra memory to prevent jvm crash during heavy Integration/unit test with newer lombok and jdk8-->
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</configuration>
</plugin>
...
</plugins>
</build>
</project>
Solution 9 - Maven
I tried the following lombok dependency on java-1.8 and java-11, and it build successfully.
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
Solution 10 - Maven
I encountered this issue when upgrading my project from JDK 8 to JDK 12 and using gradle instead of maven and using the io.franzbecker:gradle-lombok
gradle plugin to configure lombok automatically.
In this scenario changing buildScript.dependencies from classpath "io.franzbecker:gradle-lombok:1.14"
to classpath "io.franzbecker:gradle-lombok:3.2.0"
did the trick for me.
Solution 11 - Maven
I had the same issue with Java 8 and had my lombok dependency with no version at all. ALl i did was downgrade the lombok version to an older one, enough to be compatible with my Spring Boot 1.4
Solution 12 - Maven
Just check at: https://mvnrepository.com/artifact/org.projectlombok/lombok and choose newer version. For me using <version>1.18.24</version>
fixed the problem