Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven compiler not adding getters/setters(generated using Lombok) to the build jar file

Tags:

java

maven

lombok

I have the below Pojo class to which I have added the @Data from Lombok.

The Project is working fine in Eclipse IDE, and I can even see the getters/setters in the outline window of IDE. But, when I am running mvn clean install or Run As Maven Install from IDE, the jar file gets generated without any error, but there are no methods(getters, setters, equals, hashcode) which are generated by the Lombok. outline window

Since, IDE is showing the methods, there must be some issue with the maven compiler plugin in the POM file. I tried every possible solution from SO, but nothing worked.

Here is the POM:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>example</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>test-boot</name>
    <description>Demo project</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

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

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

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArgument>-proc:none</compilerArgument>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>1.3.0.Final</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>

    </build>


</project>

I have pushed the test project to the Github. Can be cloned from here: https://github.com/Puspendert/test-lambok.git

Update: To verify if the generation of getter/setter would effect anything, I changed the main method:

@SpringBootApplication
public class TestBootApplication {

    public static void main(String[] args) {            
        User user = new User();     
        user.setName("hero");
        System.out.println(user.getName());

    }    
}

and boom, as expected the project gave compilation error on mvn clean install:

[INFO] Building test-boot 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ example ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /Users/puspender/git/test-lambok/test-boot/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/puspender/git/test-lambok/test-boot/src/main/java/com/example/TestBootApplication.java:[11,21] cannot find symbol
  symbol:   method setName(java.lang.String)
  location: variable user of type com.example.User
[ERROR] /Users/puspender/git/test-lambok/test-boot/src/main/java/com/example/TestBootApplication.java:[12,40] cannot find symbol
  symbol:   method getName()
  location: variable user of type com.example.User
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

Please suggest, what could be wrong here?

like image 280
Puspender Avatar asked Sep 18 '25 08:09

Puspender


1 Answers

You are explicitly disabling annotation processing!

<compilerArgument>-proc:none</compilerArgument>

Remove this line - lombok is an annotation processing library after all - and everything (should) work file

EDIT: for fairness, there's another deleted answer (for some reason) which also suggests that

like image 198
Ori Dar Avatar answered Sep 19 '25 21:09

Ori Dar