Lombok: Spring boot does not work with Lombok - Compilation error -Werror

Created on 20 Mar 2017  路  11Comments  路  Source: projectlombok/lombok

Maven project with -Werror compiler option

COMPILATION WARNING :

No processor claimed any of these annotations: org.springframework.context.annotation, lombok.Data

COMPILATION ERROR :

warnings found and -Werror specified

Maven compiler plugin:

     `<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <showDeprecation>true</showDeprecation>
                <showWarnings>true</showWarnings>
                <compilerArgs>
                    <arg>-Werror</arg>
                    <arg>-Xlint:all</arg>
                </compilerArgs>
            </configuration>
        </plugin> `

Same issue was reported before at following link Issue1117 tried solutions provided in there but does not work.

Most helpful comment

I was able to solve similar issues in my gradle spring-boot multi-project like so:

dependencies {
    annotationProcessor("org.projectlombok:lombok")
    compileOnly("org.projectlombok:lombok")
}

Regards,
Maksim

All 11 comments

When I remove lombok dependency it compiles fine. So is the issue with spring or lombok or somewhere else.

may be its related to #1194

My project uses SpringBoot, and it works perfect with Lombok so far...

<plugins>
  <plugin>
    <groupId>com.mysema.maven</groupId>
    <artifactId>apt-maven-plugin</artifactId>
    <version>${apt-maven-plugin.version}</version>
    <executions>
      <execution>
        <goals>
          <goal>process</goal>
        </goals>
        <configuration>
          <outputDirectory>target/generated-sources/java</outputDirectory>
          <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
        </configuration>
      </execution>
    </executions>
  </plugin>
  <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
  </plugin>
</plugins>

@beamofsoul : Thanks for your reply. I did create a new mvn java project without any Spring dependencies in it. I am getting compilation error for @FunctionalInterface annotation. So this proves that there is nothing to do with Spring here. Looks like Lombok issue.

Sounds more like a java version or classpath issue

I ran into this problem with:

lombok 1.16.18
maven-compiler-plugin argument: -Werror
java: tried both 1.8.0_91 and 1.8.0_141

Including lombok as a provided dependency, without even without referencing lombok in java source, causes compile to fail if java source contains @FunctionalInterface:

Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure An unknown compilation problem occurred

I didn't see a warning in the output, just the compilation error. Removing -Werror or removing lombok resolves the problem.

I seem to be experiencing the same problem as @nguyenquoc which sounds like it may not be the same as what is reported in the issue, so perhaps it is a different issues.

It fails only during the test-compile phase of my project which seems likely because I am guessing I have a JUnit5 test with a @FunctionalInterface. Will investigate further. I'm actually running JDK9 and everything else works fine. Removing -Werror allows maven to compile my project.

 java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

Is it helpful to open a separate issue for this? I am not using Spring in this project.

Hmm, I cannot reproduce the problem.

Input files

src/main/java/HelloWorld.java

@lombok.Data
public class HelloWorld {
    int foo;

    public static void main(String... args) {
        System.out.println(new HelloWorld().getFoo());
    }

    @FunctionalInterface
    interface Foo {
        String name();
    }
}

 

lombok.config

lombok.addJavaxGeneratedAnnotation = false

 

pom.xml

<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-jdk9</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.9</java.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <showDeprecation>true</showDeprecation>
                    <showWarnings>true</showWarnings> 
                    <fork>true</fork>
                    <compilerargs>
                        <arg>-Werror</arg>
                        <arg>-Xlint:all</arg>
                        <arg>-J--add-opens=-Jjdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
                        <arg>-J--add-opens=-Jjdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
                        <arg>-J--add-opens=-Jjdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
                        <arg>-J--add-opens=-Jjdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
                        <arg>-J--add-opens=-Jjdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
                        <arg>-J--add-opens=-Jjdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
                        <arg>-J--add-opens=-Jjdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
                        <arg>-J--add-opens=-Jjdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
                        <arg>-J--add-opens=-Jjdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
                    </compilerargs>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.18</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

</project>

 

Outputs

mvn compile (after mvn clean)

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building lombok-jdk9 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ lombok-jdk9 ---

[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /shared/maven/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ lombok-jdk9 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /shared/maven/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.745 s
[INFO] Finished at: 2017-10-19T22:19:08Z
[INFO] Final Memory: 9M/23M
[INFO] ------------------------------------------------------------------------

 

java -cp target/classes HelloWorld

0

 

java -version

java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

 

mvn --version

Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T19:39:06Z)
...

I got this using Gradle.

Unknown key 'lombok.addLombokGeneratedAnnotation'

I was able to solve similar issues in my gradle spring-boot multi-project like so:

dependencies {
    annotationProcessor("org.projectlombok:lombok")
    compileOnly("org.projectlombok:lombok")
}

Regards,
Maksim

I found the same problem with lombok vs Junit5:

https://github.com/junit-team/junit5-samples/compare/master...alxn:alun/lombok

$ mvn --show-version clean test-compile
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T12:39:06-07:00)
Maven home: /Users/alun/.m2/wrapper/dists/apache-maven-3.5.0-bin/6ps54u5pnnbbpr6ds9rppcc7iv/apache-maven-3.5.0
Java version: 1.8.0_172, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.6", arch: "x86_64", family: "mac"
<snip>
[WARNING] No processor claimed any of these annotations: org.junit.jupiter.api.Test,org.junit.jupiter.params.provider.CsvSource,org.junit.jupiter.params.ParameterizedTest,org.junit.jupiter.api.DisplayName
Was this page helpful?
0 / 5 - 0 ratings