Andrey
Andrey

Reputation: 141

module-info.java does not work with lombok in Java 9

I faced problem during migration our project to Java 9.

After I've updated Java 9, I attempt to run project, I faced with compiler errors :-

Error:(6, 1) java: package javax.annotation is not visible 
(package javax.annotation is declared in module java.xml.ws.annotation, which is not in the module graph) 

but I found the solution how to resolve it. I added lombok.config file.

Then after adding module-info.java file to project compiler is displayed errors again

Error:(10, 26) java: variable title not initialized in the default constructor

Project example:

We have entity Store:

@AllArgsConstructor
@Getter
public class Story {
    private final String title;
}

in root's package I have module-info.java with content:

module javanine {
    requires lombok;
}

and in root's project I have lombok.config file with:

lombok.addJavaxGeneratedAnnotation = false
lombok.anyConstructor.suppressConstructorProperties = true

config.stopBubbling = true

and somewhere in the code I call it :

public static void main(String[] args) {
    Story story = new Story("how as");
    System.out.println(story.getTitle());
}

Upvotes: 7

Views: 7084

Answers (3)

Eugene Ryzhikov
Eugene Ryzhikov

Reputation: 17359

Just configure your module as following:

module moduleName {
    requires static lombok;
}

Upvotes: 11

Marc Magon
Marc Magon

Reputation: 848

You can include the dependency in a provided scope to enable the build, without attaching the artifact to the libraries

   <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct-processor</artifactId>
            <version>1.3.0.Final</version>
        </dependency>

Upvotes: 3

rzwitserloot
rzwitserloot

Reputation: 102832

I've done some work on fixing lombok-with-JDK9 issues, especially when you actually modularize your code (vs. just compiling java8 style code with the javac from JDK9 which has worked for a while now).

Can you give the latest edge release at https://projectlombok.org/download-edge a spin? Thanks!

Upvotes: 4

Related Questions