Springboot

[Springboot] 3.x.x maven 빌더 Lombok cannot find symbol

hand-mk 2024. 12. 12. 00:27

✔️ 서론

QueryDSL 문법도 정리하고 여러가지 지저분한 코딩 스타일을 바꾸는 것을 연습하고자 오랜만에 새로운 프로젝트를 생성했는데 진짜 엉뚱하게 @Getter 어노테이션을 선언했는데 get Method 를 cannot find symbol 이라는 에러와 함께 컴파일이 안된다. 이에 대해 해결 한 내용을 정리했다.

 

✔️ 본론

혹시나 해서 기존에 개발한 프로젝트들도 안되나 확인해봤는데, 다행히 정상적으로 컴파일 되는 것을 확인했다. 아마 새롭게 만든 프로젝트들에 한해서 이런 문제가 발생하는 것 같다.

해당 문제에 대해 찾아보니 다 gradle 빌더를 사용하는 프로젝트에 관한 해결 방안이였다. Maven 으로 공부를 시작한 사람으로써 Maven 의 시대가 가는 게 느껴진다..

그래도 꾸역꾸역 stackoverflow 를 뒤져서 찾아낸 한 글이다.

 

https://stackoverflow.com/questions/34358689/maven-build-cannot-find-symbol-when-accessing-project-lombok-annotated-methods

 

Maven build cannot find symbol when accessing project lombok annotated methods,

I'm using project lombok for the first time and I have problems compiling the project via maven when I run the build I receive errors where methods annotated with project lombok annotations are cal...

stackoverflow.com

 

나의 문제와 상당히 흡사하다.

 

해당 Questions 에 여러 원인들이 나오지만 나의 문제와는 별 연관이 없는 것 같다.

나는 Springboot 3.2.1V, JDK 17, Lombok 1.18.30 을 사용하고 있어 버전 문제는 아닌 것 같고 빌더에 문제가 있었던 것 같다.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <annotationProcessors>
          <annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
        </annotationProcessors>
      </configuration>
    </plugin>
  </plugins>
</build>

 

- annotationProcessors 를 사용하여 Maven 이 사용할 어노테이션 프로세서를 지정하였다.

💡lombok.launch.AnnotationProcessorHider$AnnotationProcessor 가 Lombok의 내부 클래스다.

 

User.java

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString(of = {"id", "name", "age"})
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column
    private String name;

    @Column
    private int age;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn
    private Team team;

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public User(String name, int age, Team team){
        this.name = name;
        this.age = age;

        if(team != null){
            team.getMembers().add(this);
        }
    }
}

 

UserRepositoryTest.java

@SpringBootTest
public class UserRepositoryTest {
    @Autowired
    UserRepository userRepository;

    @Test
    @DisplayName("유저 생성")
    void createUser(){
        User user = new User("test1", 20);
        userRepository.save(user);

        assertThat(user.getName()).isEqualTo("test1");
        assertThat(user.getAge()).isEqualTo(20);
    }
}

 

정상적으로 인식을 한다. 

 

✔️ 결어

단순 빌더 오작동이였는지 버전문제였는지 원인은 모르겠지만 한가지 배웠다.

얼른 gradle 로 넘어가야겠다..!

추후에 같은 문제가 발생하면 해결 후 내용을 수정하도록 하겠다.

'Springboot' 카테고리의 다른 글

[Springboot] springboot3 QueryDSL 정리  (0) 2025.01.05