Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lombok not working with JDK 11 modules (Jigsaw) #1723

Closed
arana198 opened this issue Jun 8, 2018 · 56 comments
Closed

Lombok not working with JDK 11 modules (Jigsaw) #1723

arana198 opened this issue Jun 8, 2018 · 56 comments

Comments

@arana198
Copy link

arana198 commented Jun 8, 2018

I'm using:

  • Java 11
  • Lombok 1.18.4 (also tried 1.18.5 edge)
  • Gradle 5.0 (also tried with 4.9)

PS: I have requires static lombok in module-info.java and IDE does not show any error

Error courtesy: @jython234

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building matrix-bridge-java 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ matrix-bridge-java ---
[INFO] Deleting /home/alejzeis/IdeaProjects/matrix-bridge-java/target
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ matrix-bridge-java ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ matrix-bridge-java ---
[WARNING] ********************************************************************************************************************
[WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *
[WARNING] ********************************************************************************************************************
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to /home/alejzeis/IdeaProjects/matrix-bridge-java/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/alejzeis/IdeaProjects/matrix-bridge-java/src/main/java/io/github/jython234/matrix/bridge/MatrixBridgeEventHandler.java:[29,32] cannot find symbol
  symbol:   method getLogger()
  location: variable bridge of type io.github.jython234.matrix.bridge.MatrixBridge
[ERROR] /home/alejzeis/IdeaProjects/matrix-bridge-java/src/main/java/io/github/jython234/matrix/bridge/MatrixBridgeEventHandler.java:[30,32] cannot find symbol
  symbol:   method getLogger()
  location: variable bridge of type io.github.jython234.matrix.bridge.MatrixBridge
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.826 s
[INFO] Finished at: 2018-05-29T22:11:26-05:00
[INFO] Final Memory: 21M/74M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project matrix-bridge-java: Compilation failure: Compilation failure:
[ERROR] /home/alejzeis/IdeaProjects/matrix-bridge-java/src/main/java/io/github/jython234/matrix/bridge/MatrixBridgeEventHandler.java:[29,32] cannot find symbol
[ERROR] symbol:   method getLogger()
[ERROR] location: variable bridge of type io.github.jython234.matrix.bridge.MatrixBridge
[ERROR] /home/alejzeis/IdeaProjects/matrix-bridge-java/src/main/java/io/github/jython234/matrix/bridge/MatrixBridgeEventHandler.java:[30,32] cannot find symbol
[ERROR] symbol:   method getLogger()
[ERROR] location: variable bridge of type io.github.jython234.matrix.bridge.MatrixBridge
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

I also have included the requires static lombok; in my module-info.java

EDIT: code can be found here: https://github.com/jython234/matrix-bridge-java

@arana198 arana198 changed the title Lombok not working JDK 10 modules Lombok not working with JDK 10 modules Jun 8, 2018
@dasAnderl
Copy link

same issue here java 10, lombok 1.18.0, mvn, module info with requires lombok
i get.

/Users/dasanderl/dev/workspaces/idea/MOD-TEST/MOD-Config/src/main/java/module-info.java:[2,18] module not found: lombok

@mahit777
Copy link

faced the same issue looks like it also depends on maven-compiler plugin because I've seen some posts that claim that they could resolve this issue by updating the version of maven-compiler. but none of them worked for me what worked was I was using mapstruct as an annotationPocessrPath the issue was gone when I removed that

@FortBlox
Copy link

FortBlox commented Jul 18, 2018

same issue here java 10, lombok 1.18.0, mvn, module info with requires lombok
i get.

Same problem. Only for me maven says that "org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile failed".
Tried downloading the edge version, still no luck. Anybody knows if/when Lombok will support Java modules?

@randakar
Copy link

randakar commented Jul 18, 2018 via email

@schoettner
Copy link

I can confirm this. I included the edge release (JDK 10, Gradle 4.9) and everything was working again as it used to with JDK 8

@markusjevringgoeuro
Copy link

When I use the latest version (1.18.2, there was no edge release when I checked), and "requires static lombok;" in my module-info.java file, when the actual code generation stops working. It doesn't generate my getters and log fields etc. I'm using maven 3.5.2, and IntelliJ IDEA. Neither of them (idea with the lombok plugin) triggers the generation of the code. Alternatively, it's triggered but it fails silently.

@FortBlox
Copy link

I was a bit busy, so only got to play around with it today. There is currently no edge release, looks like that release went on to become version 1.18.2. I tried using this version, added a "requires static lombok" to the module-info, unfortunately it didnt work. I am using java 10 modules with maven and intelliJ. It works ok if I just use java 10 without modularizing the project, but as soon as I add a module-info file, lombok stops generating the classes.

@alejzeis
Copy link

alejzeis commented Jul 27, 2018 via email

@MCMicS
Copy link

MCMicS commented Jul 29, 2018

same here. After create module-info the compilation not work with latest lombok version.
simple example: https://github.com/MCMicS/simple-lombok

  • branches with annotationprocessor, non-modulized

Hope anyone has a solution. I will look also for one

if yout add follwoing to maven-compile-plugin yout got a different error:

                        <annotationProcessorPaths>
                            <path>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                                <version>${lombok.version}</version>
                            </path>
                        </annotationProcessorPaths>

Error

javax.annotation.processing.FilerException: Cannot write to the given module.
        at jdk.compiler/com.sun.tools.javac.processing.JavacFiler.checkOrInferModule(JavacFiler.java:471)
        at jdk.compiler/com.sun.tools.javac.processing.JavacFiler.createSourceFile(JavacFiler.java:425)
        at lombok.javac.apt.LombokProcessor.forceNewRound(LombokProcessor.java:370)
        at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:357)
        at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:155)
        at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:205)
        at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:99)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:964)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:881)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.access$2100(JavacProcessingEnvironment.java:110)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1202)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1311)

IntelliJ wil show following warning (with annotation processer in pom):
Warning:java: Can't force a new processing round. Lombok won't work.

But the compilation will success.

@MCMicS
Copy link

MCMicS commented Jul 31, 2018

Update from 2018-07-31
I tried to compile by hand and compare with maven build.
If you use javac -cp lombok.jar -p lombok.jar <source> you will get the exception wiht javax.annotation.processing.FilerException: Cannot write to the given module.

The maven compiler is calle without classpath for lombok and so the compiler not found the lombok methods:

Application.java:11: error: cannot find symbol
log.info("Sample Title: " + sample.getTitle());

with annotationProcesser config within pom, the -processorpath will be set to lombok.

In my opinion we should tak ok at the javax.annotation.processing.FilerException which is raise from lombok module.

And another look should be to the compile plugin. Why is no classpath is set like the documentation says: https://projectlombok.org/setup/javac

@MCMicS
Copy link

MCMicS commented Aug 7, 2018

The maven compiler works correct to my mind because lib with modules should be only occurred in modulepath. But the annotation processers are looked up within the the classpath. So we need the setting:

<annotationProcessorPaths>
   <path>
     <groupId>org.projectlombok</groupId>
     <artifactId>lombok</artifactId>
     <version>${lombok.version}</version>
   </path>
</annotationProcessorPaths> 

There is also a discussion with annotaion processor not used if specified in module-path: http://jigsaw-dev.1059479.n5.nabble.com/Annotation-processors-and-the-processor-module-path-td5714320.html

any progress with the FilerException?
Maybe related Bug:
#1572

@MCMicS
Copy link

MCMicS commented Aug 22, 2018

I tried with edge version (1.18.3).
But now I get an additional compile error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project simple-lombok: Compilation failure
[ERROR] /lombok/dummy/ForceNewRound0.java:[1,1] file should be on source path, or on patch path for module

if I try Java11 and annotationProcessor Path I will get somer errer for mapstruct:

jdk-11\bin\javac --processor-module-path .\lib\lombok-1.18.3-edge.jar -processor lombok.launch.AnnotationProcessorHider.AnnotationProcessor --module-path .\lib\lombok-1.18.3-edge.jar -d .\javac -g --release 10 javac .conf
An exception has occurred in the compiler (11-ea). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and
the following diagnostic in your report. Thank you.
java.lang.module.ResolutionException: Module lombok does not read a module that exports org.mapstruct.ap.spi
at java.base/java.lang.module.Resolver.resolveFail(Resolver.java:885)
at java.base/java.lang.module.Resolver.checkExportSuppliers(Resolver.java:760)
at java.base/java.lang.module.Resolver.finish(Resolver.java:362)
at java.base/java.lang.module.Configuration.(Configuration.java:130)
at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:484)
at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:288)
at j

@gestshb
Copy link

gestshb commented Aug 24, 2018

i have the same problem (maven 3.5.2/jdk10/intellij 2018.2 /lombok 1.18.2) plug-in lombok installed
any solution ?

@schoettner
Copy link

Another workaround is to change the compiler plugin. Because I use Groovy for testing I had limited choice what plugins to use. The groovy-eclipse-compiler does not seem to work at the moment (it worked with the lombok 1.18.0-edge). For the gmaven-plus plugin I compiled a custom hotfix to support jdk10 and uploaded it to an internal jFrog. The fixed version of gamaven-plus works perfectly fine with all lombok versions.

@SvenWoltmann
Copy link

I found ... not a solution but rather a hack ... to get this running with Maven and JDK 9 / 10.

So first you have to add the annotation processor path, as already mentioned before:

<annotationProcessorPaths>
   <path>
     <groupId>org.projectlombok</groupId>
     <artifactId>lombok</artifactId>
     <version>${lombok.version}</version>
   </path>
</annotationProcessorPaths> 

Now I also get the "/lombok/dummy/ForceNewRound0 ... file should be on source path" error.

To fix this, I analyzed which parameters Maven passes to javac and reproduced the compilation process by directly calling javac.

I first found out that it works if you remove the "-sourcepath" parameter. However, that should not and cannot be done with Maven.

After another day of experiments, I found out that it also works if you add "/" (I assume that's where the /lombok/dummy/ForceNewRound0.java file is written to) to the sourcepath.

And that can be done with Maven ... although it's kind of hacky:

You need to add to the maven-compiler-plugin the following compiler arguments:

<compilerArgs>
	<arg>-sourcepath</arg>
	<arg>${project.basedir}/src/main/java${path.separator}${project.basedir}/target/generated-sources/annotations${path.separator}/</arg>
</compilerArgs>

This doesn't really replace the "-sourcepath" compiler argument, but it adds a second "-sourcepath", which overwrites the first one.

As I said, this is not a clean solution, but it works and maybe it's a starting point to find a real solution.

@SvenWoltmann
Copy link

Unfortunately my previous hack breaks the build in IntelliJ IDEA with javac when the project contains tests:

  • "module not found" error for each module referenced from module-info.java
  • "file should be on source path" error for each of my tests

It builds in Eclipse and in IntelliJ with the Eclipse compiler. I'll try to find a solution...

@SvenWoltmann
Copy link

Here's a way to get the hack running in Maven, IntelliJ and Eclipse:

I define the sourcepath in a separate Maven profile "update-sourcepath-for-lombok", so it's ignored by IntelliJ:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.0</version>

      <configuration>
        <annotationProcessorPaths>
          <path>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
          </path>
        </annotationProcessorPaths>
      </configuration>
    </plugin>
  </plugins>
</build>

<profiles>
  <profile>
    <id>update-sourcepath-for-lombok</id>
    <build>
      <plugins>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>

          <configuration>
            <compilerArgs>
              <arg>-sourcepath</arg>
              <arg>${project.basedir}/src/main/java${path.separator}${project.basedir}/target/generated-sources/annotations${path.separator}/</arg>
            </compilerArgs>
          </configuration>
        </plugin>
      </plugins>
    </build>
  </profile>
</profiles>

And when running Maven on the command line, I activate that profile:

mvn -Pupdate-sourcepath-for-lombok clean package

@MCMicS
Copy link

MCMicS commented Sep 3, 2018

like @SvenWoltmann mentioned the sourcepath is the problem. But if I try it with my own Annotation processors it works also with this flag. I will have a deeper look in lombok code the days.

@MCMicS
Copy link

MCMicS commented Sep 10, 2018

@rzwitserloot The problem ist that the EmptyLombokFileObject ist created and root. So the compiler warns because the root is not in source-module-paths.
Why not use the target or temp folder for ForceNewRound files?
Or maybe one of them ideas:

  • add some logic in Javac9BaseFileObjectWrapper
  • use some kind of SourceMemoryJavaFileObject

Log from lombok.javac.apt.InterceptingJavaFileManager#getJavaFileForOutput I've added:

warning: getJavaFileForOutput javaFileObject: /lombok/dummy/ForceNewRound0.java
warning: getJavaFileForOutput javaFileObject: file:///lombok/dummy/ForceNewRound0.java

In newer version for com.sun.tools.javac.processing.JavacFiler#createSourceOrClassFile you will find an implementation for module handling too.

@MCMicS
Copy link

MCMicS commented Oct 17, 2018

Tried with latest Edge Release (1.18.3 (2018-10-15 22:58:24 UTC) )

No resolution. Lombok only work in test classes in IntelliJ. Maven still fails

@matelang
Copy link

matelang commented Nov 1, 2018

I am using lombok 1.18.4 and the following still gives an error:

package io.x.cloud.exception.handler.dto;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.slf4j.MDC;
import org.springframework.http.HttpStatus;

import java.time.Instant;


/**
 * Contains the common details that should be returned in case of an error during a web service request.
 */

@JsonTypeInfo(
        use = JsonTypeInfo.Id.NAME,
        property = ErrorDto.TYPE)
@JsonSubTypes({
        @JsonSubTypes.Type(value = ErrorDto.class, name = ErrorDto.SIMPLE_TYPE),
})
@Data
@NoArgsConstructor
public class ErrorDto {
    public static final String SIMPLE_TYPE = "simple";
    public static final String TYPE = "type";

    private String requestUid = MDC.get("X-B3-TraceId");
    private long timestamp = Instant.now().toEpochMilli();
    private int httpStatus;
    private String message;
    private String errorCode = "GeneralException";

    public ErrorDto(HttpStatus httpStatus, Exception e) {
        setHttpStatus(httpStatus.value());
        setMessage(e.getMessage());
    }

    public ErrorDto(HttpStatus httpStatus, String message) {
        setHttpStatus(httpStatus.value());
        setMessage(message);
    }

    public ErrorDto(HttpStatus httpStatus, Exception e, String errorCode) {
        setHttpStatus(httpStatus.value());
        setMessage(e.getMessage());
        setErrorCode(errorCode);
    }
}

System info:

[mate@devmate ~]$ java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment (build 11.0.1+13)
OpenJDK 64-Bit Server VM (build 11.0.1+13, mixed mode)

[mate@devmate ~]$ mvn -version
Apache Maven 3.5.4 (NON-CANONICAL_2018-09-08T01:02:16+02:00_root; 2018-09-08T02:02:16+03:00)
Maven home: /opt/maven
Java version: 11.0.1, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.16-arch1-1-arch", arch: "amd64", family: "unix"
module io.x.cloud.error {
    requires static lombok;

    requires slf4j.api;

    requires hystrix.core;
    requires jackson.annotations;
    requires spring.web;
    requires spring.context;
    requires com.fasterxml.jackson.databind;
    requires feign.core;
    requires spring.core;
    requires spring.beans;
}

The build fails with the following:

[INFO] 7 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.010 s
[INFO] Finished at: 2018-11-01T12:48:30+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project x-error: Compilation failure: Compilation failure: 
[ERROR] /home/mate/work/x-cloud/x-error/src/main/java/io/x/cloud/exception/handler/dto/ErrorDto.java:[36,9] cannot find symbol
[ERROR]   symbol:   method setHttpStatus(int)
[ERROR]   location: class io.x.cloud.exception.handler.dto.ErrorDto
[ERROR] /home/mate/work/x-cloud/x-error/src/main/java/io/x/cloud/exception/handler/dto/ErrorDto.java:[37,9] cannot find symbol
[ERROR]   symbol:   method setMessage(java.lang.String)
[ERROR]   location: class io.x.cloud.exception.handler.dto.ErrorDto
[ERROR] /home/mate/work/x-cloud/x-error/src/main/java/io/x/cloud/exception/handler/dto/ErrorDto.java:[41,9] cannot find symbol
[ERROR]   symbol:   method setHttpStatus(int)
[ERROR]   location: class io.x.cloud.exception.handler.dto.ErrorDto
[ERROR] /home/mate/work/x-cloud/x-error/src/main/java/io/x/cloud/exception/handler/dto/ErrorDto.java:[42,9] cannot find symbol
[ERROR]   symbol:   method setMessage(java.lang.String)
[ERROR]   location: class io.x.cloud.exception.handler.dto.ErrorDto
[ERROR] /home/mate/work/x-cloud/x-error/src/main/java/io/x/cloud/exception/handler/dto/ErrorDto.java:[46,9] cannot find symbol
[ERROR]   symbol:   method setHttpStatus(int)
[ERROR]   location: class io.x.cloud.exception.handler.dto.ErrorDto
[ERROR] /home/mate/work/x-cloud/x-error/src/main/java/io/x/cloud/exception/handler/dto/ErrorDto.java:[47,9] cannot find symbol
[ERROR]   symbol:   method setMessage(java.lang.String)
[ERROR]   location: class io.x.cloud.exception.handler.dto.ErrorDto
[ERROR] /home/mate/work/x-cloud/x-error/src/main/java/io/x/cloud/exception/handler/dto/ErrorDto.java:[48,9] cannot find symbol
[ERROR]   symbol:   method setErrorCode(java.lang.String)
[ERROR]   location: class io.x.cloud.exception.handler.dto.ErrorDto
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Is this a known issue? If yes do we have an ETA when it will be fixed?

Unfortunately it's blocking my organization to move to a modularized project structure.

Cheers,
Mate

@ipkpjersi
Copy link

ipkpjersi commented Nov 24, 2018

Issue is still present with Java 11 and Lombok 1.18.4 and Gradle 4.10.2, I guess I'll check back in a year after Java 12 has been out for a while and hope it's fixed by then. Cheers.

@arana198 arana198 changed the title Lombok not working with JDK 10 modules Lombok not working with JDK 11 modules (Jigsaw) Dec 2, 2018
@m-radzikowski
Copy link

Hey,
using edge release I get lombok to work with Java 10 and Jigsaw modules. When building project with mvn clean package and running it with java -jar ... it works great.

But on the other hand run from IntelliJ fails with error:

/usr/lib/jvm/java-11-openjdk-amd64/bin/java -javaagent:/home/radzik/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/183.5429.30/lib/idea_rt.jar=43289:/home/radzik/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/183.5429.30/bin -Dfile.encoding=UTF-8 -p /home/radzik/Documents/lomboktest/target/classes:/home/radzik/.m2/repository/org/projectlombok/lombok/edge-SNAPSHOT/lombok-edge-20190129.004558-1.jar -m lomboktest/com.example.App
Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Module lombok does not read a module that exports org.mapstruct.ap.spi

Should it be solved in this edge release or am I doing something wrong?

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>lombok-test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <java.version>10</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <lombok.version>edge-SNAPSHOT</lombok.version>
    </properties>

    <repositories>
        <repository>
            <id>projectlombok.org</id>
            <url>https://projectlombok.org/edge-releases</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>10</release>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm</artifactId>
                        <version>6.2</version> <!-- Use newer version of ASM -->
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

module-info.java

module lomboktest {
	requires static lombok;
}

App.java

package com.example;

import lombok.Getter;

@Getter
public class App {

	private String test = "qwe";

	public static void main(String[] args) {
		System.out.println(new App().getTest());
	}
}

@bruce-stewart
Copy link

@gvart The surefire plugin works for me if I configure forkCount as zero instead of the default value of 1:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
        <!-- needed so that lombok does not throw errors during tests -->
        <forkCount>0</forkCount>
    </configuration>
</plugin>

@pavanjava
Copy link

taking the lombok edge version i have resolved the issue. below is the config i have used

org.apache.maven.plugins
maven-compiler-plugin
3.8.0

10


org.projectlombok
lombok
${lombok.version}





org.ow2.asm
asm
6.2


@vrapalis
Copy link

Hello all,

in my company we want migrate from java 8 to java 12.
Can i use at the moment lombok in gradle based project with java 12? Thanks a lot.

Best Regards.

@pentos9
Copy link

pentos9 commented Apr 10, 2019

upgrade your Lombok version, try this:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.6</version>
</dependency>

v1.18.6 and above support JDK10/11

@ipkpjersi
Copy link

ipkpjersi commented Apr 10, 2019

As I mentioned above, issue is still present with v1.18.4. Cheers.

edit: the comment above originally said v1.18.4 but has since been edited to v1.18.6, however I looked through the patch notes of v1.18.6 and saw no mention of illegal reflective access being fixed.

@imbananko
Copy link

imbananko commented Apr 11, 2019

Testing edge-snapshot and still facing an issue with private final fields
variable field not initialized in the default constructor

Class annotated with:

@Getter @Builder @JsonDeserialize(builder = Entity.EntityBuilder.class)

java 10.0.2 2018-07-17
gradle-5.1-all.zip

@pentos9
Copy link

pentos9 commented Apr 11, 2019

As I mentioned above, issue is still present with v1.18.4. Cheers.

edit: the comment above originally said v1.18.4 but has since been edited to v1.18.6, however I looked through the patch notes of v1.18.6 and saw no mention of illegal reflective access being fixed.

yes,i change the version.it is ok when i upgrade to v1.18.6

@rzwitserloot
Copy link
Collaborator

sounds like this is fixed.

@GedMarc
Copy link

GedMarc commented Jun 18, 2019

@rzwitserloot What fixed it? Still happening???!?
I've had to delombok every single one of my projects cause of this - is there any eye to fix the processing in maven?

@christian-schlichtherle
Copy link
Contributor

I'm facing the same issue, so it's definitely not fixed:

OpenJDK 11.0.2
Lombok 1.18.10

I'm going to delombok my project.

@noguespi
Copy link

Got the same issue usings jdeps (but I'm not going to delombok my project :D ).

Error: Module lombok does not read a module that exports org.mapstruct.ap.spi
jdeps failed

I haven't enough knowledge of the new java module system, I just excluded the lombok jar from jdeps analysis and fortunately it uses modules probably required by other modules. My goal is to list all the modules and build a minimal jvm runtime with minimal number of modules.

@GedMarc
Copy link

GedMarc commented Nov 14, 2019

Ok so I did get it, in JDK 12 it changes as well because service loaders are no longer read from the META-INF location anymore, only from the module file

what you want to do is

   <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven.compiler.version}</version>
                    <configuration>
                        <source>${jdk.release}</source>
                        <target>${jdk.release}</target>
                        <release>${jdk.release}</release>
                        <annotationProcessorPaths>
                            <annotationProcessorPath>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                                <version>1.18.8</version>
                            </annotationProcessorPath>
                            <path>
                                <groupId>org.mapstruct</groupId>
                                <artifactId>mapstruct-processor</artifactId>
                                <version>1.3.0.Final</version>
                            </path>
                        </annotationProcessorPaths>
                        <compilerArguments>
                            <AaddGeneratedAnnotation>false</AaddGeneratedAnnotation>
                            <Adebug>true</Adebug>
                        </compilerArguments>
                        <failOnError>true</failOnError>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.ow2.asm</groupId>
                            <artifactId>asm</artifactId>
                            <version>${maven.asm.version}</version>
                            <type>jar</type>
                        </dependency>
                    </dependencies>
                </plugin>

Then in your module-info file,

requires static lombok;

To build full JLink Images though it goes a bit further,
Rather use the maven JLink module, and reference your project as a depedency,

<profile>
            <id>jlink</id>
            <modules>
                <module>JLink</module>
            </modules>
            <build>
                <plugins>
                    <!-- JLINK -->
                    <plugin>
                        <artifactId>maven-jlink-plugin</artifactId>
                        <version>3.0.0-alpha-2-SNAPSHOT</version>
                        <extensions>true</extensions>
                        <configuration>
                            <noHeaderFiles>true</noHeaderFiles>
                            <noManPages>true</noManPages>
                            <stripDebug>true</stripDebug>
                            <verbose>true</verbose>
                            <compress>2</compress>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>org.ow2.asm</groupId>
                                <artifactId>asm</artifactId>
                                <version>${maven.asm.version}</version>
                            </dependency>
                        </dependencies>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jmod-plugin</artifactId>
                        <version>3.0.0-alpha-1</version>
                        <extensions>true</extensions>
                        <dependencies>
                            <dependency>
                                <groupId>org.ow2.asm</groupId>
                                <artifactId>asm</artifactId>
                                <version>${maven.asm.version}</version>
                            </dependency>
                        </dependencies>
                    </plugin>

                    <!-- Config your tool chain appropriately !!! -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-toolchains-plugin</artifactId>
                        <version>1.1</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>toolchain</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <toolchains>
                                <jdk>
                                    <version>1.12</version>
                                    <vendor>oracle</vendor>
                                </jdk>
                            </toolchains>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

@sleroy
Copy link

sleroy commented Dec 4, 2019

Testing edge-snapshot and still facing an issue with private final fields
variable field not initialized in the default constructor

Class annotated with:

@Getter @Builder @JsonDeserialize(builder = Entity.EntityBuilder.class)

java 10.0.2 2018-07-17 gradle-5.1-all.zip

I had the same recently in 1.18.10 and JDK 11

@blankhang
Copy link

same error with jdk11 and lombok 1.18.12

15:33:52  [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ common ---
15:33:52  [INFO] Changes detected - recompiling the module!
15:33:54  [INFO] -------------------------------------------------------------
15:33:54  [ERROR] COMPILATION ERROR : 
15:33:54  [INFO] -------------------------------------------------------------
15:33:54  [ERROR] 
15:33:54  [ERROR] model/AutoCount.java:[124,30] cannot find symbol

@GedMarc
Copy link

GedMarc commented Apr 23, 2020

No I have Lombok fully supported and installed on 1.18.12 from jdk11 all the way through to jdk14.

Double check your config and make sure you are referencing the Lombok annotation processor in your maven compiler config.

It will not automatically pick up the annotation processor, especially from 12 and up as the meta-inf/services directory can longer be referenced at all for service discovery.

@blankhang
Copy link

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.12</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>

(like this)[https://projectlombok.org/setup/maven]

I have been tried a lot of methods but still getting the same error
and I don't know why

@GedMarc
Copy link

GedMarc commented Apr 23, 2020

try this

  <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <annotationProcessorPath>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </annotationProcessorPath>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${mapstruct.version}</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArguments>
                        <AaddGeneratedAnnotation>false</AaddGeneratedAnnotation>
                        <Adebug>true</Adebug>
                    </compilerArguments>
                </configuration>
            </plugin>

@blankhang
Copy link

my bad it was not caused by lombok
it's code issues
after update code
I can run mvn package with no error just like this

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>

thanks bro

@micahrockyfort
Copy link

micahrockyfort commented Jun 24, 2020

Hello, I am also still having errors using lombok 1.18.12 from OpenJDK11. I've tried the solutions above but it still does not work.

<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<configuration>
		<source>11</source>
		<target>11</target>
		<compilerVersion>11</compilerVersion>
		<annotationProcessorPaths>
			<annotationProcessorPath>
				<groupId>org.projectlombok</groupId>
				<artifactId>lombok</artifactId>
				<version>1.18.12</version>
			</annotationProcessorPath>
			<path>
				<groupId>org.mapstruct</groupId>
				<artifactId>mapstruct-processor</artifactId>
				<version>1.3.0.Final</version>
			</path>
		</annotationProcessorPaths>
		<compilerArguments>
			<AaddGeneratedAnnotation>false</AaddGeneratedAnnotation>
			<Adebug>true</Adebug>
		</compilerArguments>
	</configuration>
</plugin>

@Auties00
Copy link

Hello, I'm facing this issue on Java 15. Is there any fix?

@vchepeli
Copy link

vchepeli commented Apr 7, 2021

I have same issue with Adopt JDK11 and MVN 3.6.3, not possible to compile

@chrylis
Copy link

chrylis commented Aug 9, 2021

Same with Adopt 11.0.11, maven-compiler-plugin 3.8.1, and Lombok 1.18.20: Modifications aren't inserted, leading to symbol not found errors. It's working fine from within Eclipse using ecj.

@projectlombok projectlombok deleted a comment from onacit May 5, 2022
@rzwitserloot
Copy link
Collaborator

Cannot reproduce. Will remain closed without a complete reproduction formula. A zip with the lot - maven file, everything.

@shahnawazm786
Copy link

I am facing the same issue while using JDK11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests