Lombok: Java 11 jigsaw modules

Created on 13 Nov 2018  路  8Comments  路  Source: projectlombok/lombok

We are using Java 11.0.1 and Maven 3.6.0.

When trying to build a java module with module-info.java we created and at first lombok didn't work. However after adding annotationProcessorPaths it gets further along but then we are getting:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /lombok/dummy/ForceNewRound0.java:[1,1] file should be on source path, or on patch path for module

It seems that a problem is with the following lombok code:

    // Force a new round to reset resolution. The next round will cause this method (process) to be called again.
    forceNewRound((JavacFiler) processingEnv.getFiler());
    private void forceNewRound(JavacFiler filer) {
           if (!filer.newFiles()) {
                   try {
                           JavaFileObject dummy = filer.createSourceFile("lombok.dummy.ForceNewRound" + (dummyCount++));
                           Writer w = dummy.openWriter();
                           w.close();
                   } catch (Exception e) {
                           e.printStackTrace();
                           processingEnv.getMessager().printMessage(Kind.WARNING,
                                           "Can't force a new processing round. Lombok won't work.");
                   }
           }
   }

It seems that this is just some hack that is created a problematic java file to force new round of processing. Can this be replaced with some other (internal?) API?

Any chance to get this fixed somehow? Or some working workaround.
There is a workaround with -sourcepath, but it is messing with IntelliJ (I get modules not found).

parked

Most helpful comment

Tested with 1.18.6:

  • sourcepath is fixed
  • annotation processing is still required
  • surefire is still failing due to missing org.mapstruct.ap.spi
    (would it be possible to just add dependency for mapstruct-processor to pom?)

Another possible workaround for last error is adding (instead of forkCount = 0 workaround):

    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-processor</artifactId>
        <version>1.2.0.Final</version>
        <scope>provided</scope>
    </dependency>

All 8 comments

@matejsp could you please share the workaround?

Sure

Recap of Lombok issues (maven + java 11):

  • maven surefire problem when running unit tests (WORKAROUND: forkCount = 0)
  • lombok not picked up as annotation processor (WORKAROUND: add annotationProcessorPaths)
  • getting file should be on source path (WORKAROUND: add sourcepath ... but problematic in IntelliJ)
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <!-- fix for running unit tests ([ERROR] The forked VM terminated 
                         without properly saying goodbye. VM crash or System.exit called?) 
                         [DEBUG] Error occurred during initialization of boot layer
                         [DEBUG] java.lang.module.ResolutionException: Module lombok does not read a module that exports org.mapstruct.ap.spi  -->
                    <forkCount>0</forkCount>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.4</version>
                        </path>
                    </annotationProcessorPaths>
                    <!-- this helps when getting error: file should be on source path, or on patch path for module -->
                    <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>

Another possible workaround with IntelliJ workaround (disable profile: [ ] update-sourcepath-for-lombok in Maven -> Profiles toolbox).

    <properties>
        <forkCount>0</forkCount>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.4</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <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>

We just released an edge release. Can you give it a try and report back:

  • if it fixes the problem
  • if everything else still works as expected

Quick retest:

  • maven surefire problem when running unit tests (WORKAROUND: forkCount = 0)
    NOT FIXED

Using latest surefire 3.0.0-M3 (run with mvn clean package -X and execute surefire command by hand)

Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Module lombok does not read a module that exports org.mapstruct.ap.spi

content of a file that is run from surefire when forking: java @surefireargsXXXXXXXX

"/Users/xxxxx/projects/somecompany-moduleA/moduleA-api/target/classes:/Users/xxxxx/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.9.8/jackson-annotations-2.9.8.jar:/Users/xxxxx/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.2.Final/hibernate-jpa-2.1-api-1.0.2.Final.jar:/Users/xxxxx/.m2/repository/org/projectlombok/lombok/edge-SNAPSHOT/lombok-edge-SNAPSHOT.jar"
--class-path
"/Users/xxxxx/.m2/repository/org/apache/maven/surefire/surefire-booter/3.0.0-M3/surefire-booter-3.0.0-M3.jar:/Users/xxxxx/.m2/repository/org/apache/maven/surefire/surefire-api/3.0.0-M3/surefire-api-3.0.0-M3.jar:/Users/xxxxx/.m2/repository/org/apache/maven/surefire/surefire-logger-api/3.0.0-M3/surefire-logger-api-3.0.0-M3.jar:/Users/xxxxx/projects/somecompany-moduleA/moduleA-api/target/test-classes:/Users/xxxxx/.m2/repository/javax/validation/validation-api/2.0.1.Final/validation-api-2.0.1.Final.jar:/Users/xxxxx/.m2/repository/com/nimbusds/nimbus-jose-jwt/6.7/nimbus-jose-jwt-6.7.jar:/Users/xxxxx/.m2/repository/com/github/stephenc/jcip/jcip-annotations/1.0-1/jcip-annotations-1.0-1.jar:/Users/xxxxx/.m2/repository/net/minidev/json-smart/2.3/json-smart-2.3.jar:/Users/xxxxx/.m2/repository/net/minidev/accessors-smart/1.2/accessors-smart-1.2.jar:/Users/xxxxx/.m2/repository/org/ow2/asm/asm/5.0.4/asm-5.0.4.jar:/Users/xxxxx/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.60/bcprov-jdk15on-1.60.jar:/Users/xxxxx/.m2/repository/io/micrometer/micrometer-core/1.1.2/micrometer-core-1.1.2.jar:/Users/xxxxx/.m2/repository/org/hdrhistogram/HdrHistogram/2.1.9/HdrHistogram-2.1.9.jar:/Users/xxxxx/.m2/repository/org/latencyutils/LatencyUtils/2.0.3/LatencyUtils-2.0.3.jar:/Users/xxxxx/.m2/repository/com/jayway/jsonpath/json-path/2.4.0/json-path-2.4.0.jar:/Users/xxxxx/.m2/repository/org/assertj/assertj-core/3.11.1/assertj-core-3.11.1.jar:/Users/xxxxx/.m2/repository/org/mockito/mockito-core/2.23.4/mockito-core-2.23.4.jar:/Users/xxxxx/.m2/repository/net/bytebuddy/byte-buddy/1.9.7/byte-buddy-1.9.7.jar:/Users/xxxxx/.m2/repository/net/bytebuddy/byte-buddy-agent/1.9.7/byte-buddy-agent-1.9.7.jar:/Users/xxxxx/.m2/repository/org/objenesis/objenesis/2.6/objenesis-2.6.jar:/Users/xxxxx/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/Users/xxxxx/.m2/repository/org/hamcrest/hamcrest-library/1.3/hamcrest-library-1.3.jar:/Users/xxxxx/.m2/repository/org/skyscreamer/jsonassert/1.5.0/jsonassert-1.5.0.jar:/Users/xxxxx/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar:/Users/xxxxx/.m2/repository/org/springframework/spring-test/5.1.4.RELEASE/spring-test-5.1.4.RELEASE.jar:/Users/xxxxx/.m2/repository/org/xmlunit/xmlunit-core/2.6.2/xmlunit-core-2.6.2.jar:/Users/xxxxx/.m2/repository/javax/xml/bind/jaxb-api/2.3.1/jaxb-api-2.3.1.jar:/Users/xxxxx/.m2/repository/javax/activation/javax.activation-api/1.2.0/javax.activation-api-1.2.0.jar:/Users/xxxxx/.m2/repository/com/zaxxer/HikariCP/3.2.0/HikariCP-3.2.0.jar:/Users/xxxxx/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.9.8/jackson-datatype-jdk8-2.9.8.jar:/Users/xxxxx/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.9.8/jackson-core-2.9.8.jar:/Users/xxxxx/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.9.8/jackson-databind-2.9.8.jar:/Users/xxxxx/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.9.8/jackson-datatype-jsr310-2.9.8.jar:/Users/xxxxx/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar:/Users/xxxxx/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.3.2/junit-jupiter-engine-5.3.2.jar:/Users/xxxxx/.m2/repository/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.jar:/Users/xxxxx/.m2/repository/org/junit/platform/junit-platform-engine/1.3.2/junit-platform-engine-1.3.2.jar:/Users/xxxxx/.m2/repository/org/junit/platform/junit-platform-commons/1.3.2/junit-platform-commons-1.3.2.jar:/Users/xxxxx/.m2/repository/org/opentest4j/opentest4j/1.1.1/opentest4j-1.1.1.jar:/Users/xxxxx/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.3.2/junit-jupiter-api-5.3.2.jar:/Users/xxxxx/.m2/repository/org/junit/vintage/junit-vintage-engine/5.3.2/junit-vintage-engine-5.3.2.jar:/Users/xxxxx/.m2/repository/junit/junit/4.12/junit-4.12.jar:/Users/xxxxx/.m2/repository/org/apache/maven/surefire/surefire-junit-platform/3.0.0-M3/surefire-junit-platform-3.0.0-M3.jar:/Users/xxxxx/.m2/repository/org/apache/maven/surefire/common-java5/3.0.0-M3/common-java5-3.0.0-M3.jar:/Users/xxxxx/.m2/repository/org/junit/platform/junit-platform-launcher/1.3.1/junit-platform-launcher-1.3.1.jar"
--patch-module
somecompany.moduleA.api="/Users/xxxxx/projects/somecompany-moduleA/moduleA-api/target/test-classes"
--add-exports
somecompany.moduleA.api/net.somecompany.test=ALL-UNNAMED
--add-modules
somecompany.moduleA.api
--add-reads
somecompany.moduleA.api=ALL-UNNAMED
  • lombok not picked up as annotation processor (WORKAROUND: add annotationProcessorPaths)
    NOT FIXED
  • getting file should be on source path (WORKAROUND: add sourcepath ... but problematic in IntelliJ)
    FIXED

I can see a bit of progress 馃憤

I will retest with next EDGE when available.

Tested with 1.18.6:

  • sourcepath is fixed
  • annotation processing is still required
  • surefire is still failing due to missing org.mapstruct.ap.spi
    (would it be possible to just add dependency for mapstruct-processor to pom?)

Another possible workaround for last error is adding (instead of forkCount = 0 workaround):

    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-processor</artifactId>
        <version>1.2.0.Final</version>
        <scope>provided</scope>
    </dependency>

Duplicate of #2231

Was this page helpful?
0 / 5 - 0 ratings