Skip to content
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

[BUG] 'Symbol' not recognized. Getters and Setters. #3804

Open
patrickfeeney03 opened this issue Jan 1, 2025 · 15 comments
Open

[BUG] 'Symbol' not recognized. Getters and Setters. #3804

patrickfeeney03 opened this issue Jan 1, 2025 · 15 comments

Comments

@patrickfeeney03
Copy link

patrickfeeney03 commented Jan 1, 2025

Describe the bug
Getters and setters are not being created. Seems to work fine until compilation. If I comment out a plugin in the Pom file the issue goes away. This has happened to other colleagues recently (last week).

To Reproduce
Create a Spring project with Maven and Java 21. With dependencies Spring Boot DevTools, Lombok, Spring Web, JDBC API, Spring Data JPA, MySQL Driver, Spring for RabbitMQ, Validation, CycloneDX SBOM support, Cloud Bootstrap, OpenFeign.
This is the Pom that I am using. You can see the commented out lines. If I don't do this I will get errors saying java: cannot find symbol symbol: method getName(). For all of setters and getters that are supposed to be created with Lombok @DaTa
Usage example: user.setName(signUpRequest.getName());

<?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 https://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>3.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>ie.atu</groupId>
    <artifactId>auth-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>auth-service</name>
    <description>auth-service</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>21</java.version>
        <spring-cloud.version>2024.0.0</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <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>-->
            <plugin>
                <groupId>org.cyclonedx</groupId>
                <artifactId>cyclonedx-maven-plugin</artifactId>
            </plugin>
            <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>

Expected behavior
I expected that after creating the project using the generation provided by Intellij I would be able to use the setters and getters from Lombok. I did not manually modify the POM.

@patrickfeeney03
Copy link
Author

image

@sabaja
Copy link

sabaja commented Jan 5, 2025

Here I'm with same problem as @patrickfeeney03, I tried several projects with spring boot 3.4.1, java 21, maven h2/postgres/mysql, jpa/hibernate, kafka and so on.. but org.projectlombok:lombok:1.18.36 is no longer working properly.
During compile time everything seems ok, but at runtime time the exception cannot find the symbol
image

@patrickfeeney03
Copy link
Author

Here I'm with same problem as @patrickfeeney03, I tried several projects with spring boot 3.4.1, java 21, maven h2/postgres/mysql, jpa/hibernate, kafka and so on.. but lombok is no longer working properly.
During compile time everything seems ok, but at runtime time the exception cannot find the symbol
image

Try commenting out what I commented out in my pom. May help you. For now ...

@dinmukhamed1729
Copy link

dinmukhamed1729 commented Jan 10, 2025

Это сработало, но не уверен, почему именно. Возможно, дело в зависимости или конфигурации, которую я добавил, но я не разбирался в этом глубже.
Вот как я сделал:

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

@khanhoit
Copy link

you need set detail version of lombok and add dependency lombok detail
image

@patrickfeeney03
Copy link
Author

you need set detail version of lombok and add dependency lombok detail image

yeah buy why would you need to specify the version. The project creation tool is supposed to handle all of this.

@hfyZone
Copy link

hfyZone commented Jan 16, 2025

I have the same problem.And my project uses idk 17, when I run 'mvn clean install' ,all the getters and setters can't be found.i tried everything on the web but none of them are helpful.I am afraid I have to use jkd1.8 and springboot2 for a probably well functioned Lombok or just write all the getters and setters by myself 😭

@patrickfeeney03
Copy link
Author

I have the same problem.And my project uses idk 17, when I run 'mvn clean install' ,all the getters and setters can't be found.i tried everything on the web but none of them are helpful.I am afraid I have to use jkd1.8 and springboot2 for a probably well functioned Lombok or just write all the getters and setters by myself 😭

try to do what I did. It's at the very top of this, in the pom file. lmk

@Brando333
Copy link

I didn't have problems using Lombok in simple java proyects but when I used it with Spring I got the problem and fixed it using this :

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

@AASHIK-2512
Copy link

org.projectlombok lombok annotationProcessor

even using this not solving my issue help me to do what to do ?

@Rawi01
Copy link
Collaborator

Rawi01 commented Jan 25, 2025

For JDKs <= 22 without modules you can simply include lombok as a provided or optional dependency and you are done. Everything works out of the box.

For projects using modules you have to explicit enable lombok by adding it to the annotationProcessorPaths and as a dependency. If you use Spring Boot and a recent maven version you can skip the version number, otherwise you should create a lombok.version property and add that one to the dependency and the annotation processor.

If you use a JDK >= 23 you have to use the module version or set <proc>full</proc> in the compiler plugin configuration.

@Brando333 @dinmukhamed1729 There is no annotationProcessor scope in maven.

@lamgtax01
Copy link

I didn't have problems using Lombok in simple java proyects but when I used it with Spring I got the problem and fixed it using this :

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

When I added in pom.xml, it stay red. mouse over shows: Cannot resolve symbol 'annotationProcessor'

@Brando333
Copy link

@Rawi01 @lamgtax01

Image

In older versions of Maven (or the maven-compiler-plugin), the annotationProcessor attribute is not a valid scope. The standard scopes in Maven are: compile, provided, runtime, test, and system.

If you use a version of Maven or the Compiler Plugin older than 3.5, the element does not exist, and attempting to use annotationProcessor will fail because Maven does not recognize it.

Ensure you are using Maven 3.6+ and maven-compiler-plugin 3.5+.

@Rawi01
Copy link
Collaborator

Rawi01 commented Jan 30, 2025

@Brando333 No, there is no scope like this, the maven version doesn't matter. See https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope for a full list of scopes.

@dinmukhamed1729
Copy link

Попробуй это походу дело в том что нужно связать mupstruct и lombok

 <dependencies>

        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>1.6.0.Beta2</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.32</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-mapstruct-binding</artifactId>
            <version>0.2.0</version>
        </dependency>

        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>

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


        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.4.0-b180830.0359</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>1.6.0.Beta2</version>
                        </path>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.32</version>
                        </path>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok-mapstruct-binding</artifactId>
                            <version>0.2.0</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>

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

9 participants