Lombok methods don’t get generated in classes while building spring boot module using them

Springboot 3.1.2
Java 17

I have a parent project containing two modules

Parent pom:

<project ...>
    <groupId>com.demo</groupId>
    <artifactId>prnt</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>prnt</name>
    <description>Parent module</description>

    <modules>
        <module>common</module>
        <module>module_one</module>
    </modules>
</project>

common pom:

<project ...>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.2</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.demo</groupId>
    <artifactId>common</artifactId>
    <packaging>jar</packaging>
    <name>common</name>
    <description>Common Module</description>

    <properties>
        <java.version>17</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>
            <optional>true</optional>
        </dependency>
    </dependencies>
</project>

module_one pom:

<project ...>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.2</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.demo</groupId>
    <artifactId>module_one</artifactId>
    <packaging>jar</packaging>
    <name>module_one</name>
    <description>Module 1</description>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.demo</groupId>
            <artifactId>common</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

module_one module-info:

open module com.demo.module_one {
    requires com.demo.common;
    uses com.demo.common.src.model.User;
}

com.demo.common is supposed to be a shared library and com.demo.module_one an executable applciation.

com.demo.common.src.model.User uses @lombok.Builder and @lombok.Data

While running module_one as a spring boot application, everything works properly. Every instance of User in module_one can call .builder, and all .get and .set methods. However, while building module_one with mvn clean install, the lombok methods are not generated and cause compilation failures becasue of symbol not found errors being thrown.

I have tried:

  • Adding requires static lombok; to module_one’s module-info.
  • Keeping the lombok dependency and removing the lombok exclusion in module_one’s pom, vice-versa and removing them both.
  • Using every permutation of the provided scope for the lombok dependency in common and module_one’s poms.
  • Using the regular maven plugin, as opposed to spring boot maven, along with the lombok annotaion processor as recommended here.

Nothing seems to work…

  • Module One shouldn’t be bothered with Lombok to begin with, that should all be part of your common module. The exposed files will have the code generated before it is put into the module.

    – 

  • I’m am facing this error even if the lombok dependency and exclusion are exculded in module_one’s pom. Project/main/prnt/module_one/src/main/java/com/demo/module_one/processor/UserProcessor.java:[10,10] cannot find symbol [ERROR] symbol: method builder() [ERROR] location: class com.demo.common.src.model.User

    – 

  • Then there is something wrong with your setup. Where are you building this, command line, ide etc. Also you aren’t following the lombok documentation on how to configure things -> projectlombok.org/setup/maven

    – 

Leave a Comment