5

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());
}
Naman
  • 27,789
  • 26
  • 218
  • 353
Andrey
  • 121
  • 2
  • 5
  • Hi @nullpointer I even couldn't build project. Error:(10, 26) java: variable title not initialized in the default constructor. Finally compiler shows this errors Error:(8, 23) java: constructor Story in class com.test.model.Story cannot be applied to given types; required: no arguments found: java.lang.String reason: actual and formal argument lists differ in length and this Error:(10, 26) java: variable title not initialized in the default constructor – Andrey Nov 23 '17 at 17:22
  • That's what is missing from the question. How do you build the project and what error do you get while building. Maybe add the stacktrace. – Naman Nov 23 '17 at 17:23
  • @nullpointer I try to start it in IDE and it's failed. Example of project I provide – Andrey Nov 23 '17 at 17:40
  • 1
    I don't know if lombak has support for JDK 9, there is a lengthy issue tracking it here: https://github.com/rzwitserloot/lombok/issues/985 – Alan Bateman Nov 23 '17 at 18:25
  • 1
    This might just end up being a duplicate of https://stackoverflow.com/questions/41520511/does-project-lombok-support-java-9. Though the problem description has some other aspect remaining as well. – Naman Nov 23 '17 at 18:29
  • @Andrey: I agree with nullpointer, it looks like your problems are entirely Lombok based. As Alan and [this answer](https://stackoverflow.com/a/41521711/2525313) state, have a look at [the Lombok issue for Java 9 support](https://github.com/rzwitserloot/lombok/issues/985) for a discussion of how to make it work, particularly [this comment](https://github.com/rzwitserloot/lombok/issues/985#issuecomment-337741287). – Nicolai Parlog Nov 27 '17 at 08:51

3 Answers3

10

Just configure your module as following:

module moduleName {
    requires static lombok;
}

Eugene Ryzhikov
  • 17,131
  • 3
  • 38
  • 60
  • Some extra explanation for people like me using Lombok with Maven and Java 9+'s module system: You may have gone to the [getting started with Maven](https://projectlombok.org/setup/maven) page but you also needed to follow the [javac](https://projectlombok.org/setup/javac) instructions (which is what this answer explains). – Captain Man Jun 01 '20 at 18:01
4

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!

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
  • 2
    now when I indicate requires lombok; in the modul-info.java file, the code is compiled but I receive the next: " Error occurred during initialization of boot layer java.lang.module.ResolutionException: Module lombok does not read a module that exports org.mapstruct.ap.spi". And during maven compilation it's swears at "Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project some: Compilation failure" – Andrey Feb 13 '18 at 19:22
  • https://projectlombok.org/edge-releases does not work at all. Any father hints how to solve an issue with lombok and modules? – tomasz-mer Nov 09 '18 at 15:19
  • I'm not sure where you got that URL from, but it is not a correct URL. Try: https://projectlombok.org/download-edge – rzwitserloot Nov 20 '18 at 15:50
3

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>
Marc Magon
  • 713
  • 7
  • 11