Skip to content

Spring boot does not work with Lombok - Compilation error -Werror #1339

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

Open
nchavan opened this issue Mar 20, 2017 · 12 comments
Open

Spring boot does not work with Lombok - Compilation error -Werror #1339

nchavan opened this issue Mar 20, 2017 · 12 comments

Comments

@nchavan
Copy link

nchavan commented Mar 20, 2017

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.

@nchavan
Copy link
Author

nchavan commented Mar 20, 2017

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

@mtbadi39
Copy link

may be its related to #1194

@beamofsoul
Copy link

beamofsoul commented Mar 23, 2017

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>

@nchavan
Copy link
Author

nchavan commented Mar 23, 2017

@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.

@schauder
Copy link

Sounds more like a java version or classpath issue

@nguyenquoc
Copy link

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.

@jhovell
Copy link

jhovell commented Oct 17, 2017

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.

@rspilker
Copy link
Collaborator

rspilker commented Oct 19, 2017

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)
...

@robertop87
Copy link

I got this using Gradle.

Unknown key 'lombok.addLombokGeneratedAnnotation'

@daggerok
Copy link

daggerok commented May 3, 2018

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

@alxn
Copy link

alxn commented Aug 14, 2018

I found the same problem with lombok vs Junit5:

junit-team/junit5-samples@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

@selimppc
Copy link

In the new version of Spring Boot 3.x.x, spring-boot-maven-plugin configuration explicitly excludes Lombok.

I had the same issue in the version of Spring boot 3.4.0. I solved the issue by removing the spring-boot-maven-plugin from my pom.xml:

see my configuration (pom.xml):

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

and the Entity:

import lombok.*;

@Data
public class Tag {
    private Long id;
    private String name;
}

Result:

$ mvn clean install

....
[INFO] ---------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ---------------------------------------------------------------

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