[Error] Spring Boot Gradle 프로젝트 Test 코드 lombok 사용 안됨 해결
by coco3o반응형
IntelliJ Gradle 프로젝트를 진행하던 중 Test 코드에 lombok 사용이 안되는 문제가 있었습니다.


위와같이 Test 가 아닌 곳에서는 사용이 잘 되지만, Test 에서는 lombok이 import가 되지 않았습니다.
셋팅한 build.gradle은 아래와 같습니다.
plugins { id 'org.springframework.boot' version '2.5.4' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' id 'war' } group = 'org.coco' version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' configurations { compileOnly { extendsFrom annotationProcessor } } repositories { mavenCentral() } dependencies { implementation 'mysql:mysql-connector-java' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' developmentOnly 'org.springframework.boot:spring-boot-devtools' providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' testImplementation 'org.springframework.boot:spring-boot-starter-test' annotationProcessor 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok' } test { useJUnitPlatform() }
결론부터 말하면, dependencies 에 testCompileOnly 와 testAnnotationProcessor가 없었기 때문에
Test 에서 lombok이 import 되지 않았던 것이었습니다.
dependencies에 아래와 같이 test 를 추가해줍니다.
dependencies { implementation 'mysql:mysql-connector-java' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' developmentOnly 'org.springframework.boot:spring-boot-devtools' providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' testImplementation 'org.springframework.boot:spring-boot-starter-test' //test 추가 annotationProcessor 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' testCompileOnly 'org.projectlombok:lombok' }
위와같이 추가 후 build 했을 때, 만약 아래와 같은 에러가 나온다면 아래와 같이 괄호로 묶어서 build 해보세요.

dependencies { implementation 'mysql:mysql-connector-java' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' developmentOnly 'org.springframework.boot:spring-boot-devtools' providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' testImplementation 'org.springframework.boot:spring-boot-starter-test' //괄호로 묶어서 build compileOnly("org.projectlombok:lombok") annotationProcessor("org.projectlombok:lombok") testCompileOnly("org.projectlombok:lombok") testAnnotationProcessor("org.projectlombok:lombok") }


이제 Test 코드에서도 lombok을 사용할 수 있습니다.
블로그의 정보
슬기로운 개발생활
coco3o