java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment [duplicate]
Switch to at least the 1.18.22
version of Lombok that contains the fix
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
To see the last version of lombok, follow this link on search.maven.org
@FrankyFred has provided a temporary solution to be able to use Lombok: https://stackoverflow.com/a/66981165/12586904
As far as my research goes and the various responses that I received to this question, it seems like there is no possible way of running Lombok currently in OpenJDK 16. As such, an alternative to using Lombok is to put the @data
methods manually in your code. The following link briefly explains how to do this in case you are new to this topic: https://javabydeveloper.com/lombok-data-annotation/#:~:text=Lombok%20Data%20annotation%20(%20%40Data%20),as%20well%20as%20a%20constructor.
Sample pseudo code representing what @Data
really represents:
@Getter @Setter
@RequiredArgsConstructor
@ToString
@EqualsAndHashCode
public class User1 {
private Long id;
private String username;
}
The Lombok @Data
annotation minimizes the usage of more annotations when you need to generate all the above seven requirements, but they essentially achieve the same objectives when running the code.
I am by no means an expert at this, but hopefully, this will help anyone else who gets stuck using Lombok but needs to find an alternative since their book/tutorial might utilize it and u would still like to continue with the book/tutorial.
It seems can be solved by adding plugin in pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>16</source>
<target>16</target>
<!-- <release>16</release>-->
<fork>true</fork>
<compilerArgs>
<arg>--enable-preview</arg>
<arg>-Xlint:all</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED</arg>
</compilerArgs>
<!--for unmappable characters in classes-->
<encoding>UTF-8</encoding>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<!--for lombok annotations to resolve-->
<!--contradictory to maven, intelliJ fails with this-->
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
solution from Lombok's access to jdk.compiler's internal packages incompatible with Java-16