스프링부트와 gradle 그레이들을 사용하는 프로젝트를 진행 중입니다.
@Slf4j 어노테이션은 롬복에서 지원해주는 로깅 어노테이션으로 많이들 사용합니다.
그런데 TEST 에서 사용을 하려고 하면 @Slf4j 가 자동으로 임포트 목록에 뜨지 않는 경우가 있습니다.
원인은 바로 그레이들 설정 때문입니다.
메이븐 같은 경우에는 <scope> 라는 범위 지정이 있는데 반면 그레이들은 compile, compileonly, annotationProcessor 등으로 나눠져있습니다.
//annotationProcessor 'org.projectlombok:lombok'
compile('org.projectlombok:lombok')
처음에는 annotationProcessor 로 되어 있었는데 이를 compile 로 변경하니깐 임포트 목록에 정상적으로 나오게 됩니다.
정상적으로 출력된 모습.
아래는 그레이들의 구성목록입니다.
annotationProcessor 는 컴파일 시점으로 코드를 생성하며, 이렇게 설정을 하지 않으면 롬복을 포함한 프로젝트를 export할 때 롬복에서 제공되는 에노테이션 전부가 포함되지 않는다 라고 합니다.
즉, 배포할 때는 필요로 하게 되는 설정같습니다.
compileOnly 를 할때도 test 클래스에서 나오지 않습니다.
complileOnly 는 Gradle이 컴파일 클래스 경로에만 종속성을 추가 한다고 합니다.
처음에는 annotationProcessor 이 원인인 줄 알았지만 compile 설정을 안해줘서 나오지 않았던 것 입니다.
compile('org.projectlombok:lombok')
annotationProcessor 'org.projectlombok:lombok'
현재는 이렇게 설정을 맞췄습니다.
아래는 그레이들의 구성목록을 가져와봤습니다.
compile : 프로젝트를 컴파일할 때 필요한 의존 라이브러리들
compileOnly : Gradle이 컴파일 클래스 경로에만 종속성을 추가합니다(빌드 출력에 추가되지 않음).
runtime : 프로젝트를 실행할 때 필요한 의존 라이브러리들. 기본적으로 compile을 모두 포함한다.
runtimeOnly : Gradle이 런타임 시에 사용하도록 빌드 출력에만 종속성을 추가합니다.
testCompile : 프로젝트의 테스트를 컴파일할 때 필요한 라이브러리들. 기본적으로 프로젝트의 컴파일된 클래스들과 compile 의존성을 포함한다.
testRuntime : 프로젝트의 테스트를 실행할 때 필요한 라이브러리들. 기본적으로 compile, runtime, testCompile 의존성을 포함한다.
annotationProcessor : 주석 프로세서인 라이브러리에 종속성을 추가하려면 반드시 annotationProcessor
구성을 사용하여 주석 프로세서 클래스 경로에 추가해야 합니다. 그 이유는 이 구성을 사용하면 컴파일 클래스 경로를 주석 프로세서 클래스 경로와 분리하여 빌드 성능을 향상할 수 있기 때문입니다.
Configuration name | Role | Consumable? | Resolvable? | Description |
---|---|---|---|---|
|
Declaring API dependencies |
no |
no |
This is where you should declare dependencies which are transitively exported to consumers, for compile. |
|
Declaring implementation dependencies |
no |
no |
This is where you should declare dependencies which are purely internal and not meant to be exposed to consumers. |
|
Declaring compile only dependencies |
yes |
yes |
This is where you should declare dependencies which are only required at compile time, but should not leak into the runtime. This typically includes dependencies which are shaded when found at runtime. |
|
Declaring runtime dependencies |
no |
no |
This is where you should declare dependencies which are only required at runtime, and not at compile time. |
|
Test dependencies |
no |
no |
This is where you should declare dependencies which are used to compile tests. |
|
Declaring test compile only dependencies |
yes |
yes |
This is where you should declare dependencies which are only required at test compile time, but should not leak into the runtime. This typically includes dependencies which are shaded when found at runtime. |
|
Declaring test runtime dependencies |
no |
no |
This is where you should declare dependencies which are only required at test runtime, and not at test compile time. |
출처 : https://docs.gradle.org/4.10.2/userguide/java_library_plugin.html#java_library_plugin
'개발자의 공부방 > 스프링' 카테고리의 다른 글
스프링부트] 목록 리스트 (0) | 2020.03.26 |
---|---|
Mybatis] 끄적끄적 (0) | 2020.03.20 |
스프링] 의존성 주입 방법 여러가지. (0) | 2020.03.17 |
스프링부트 에러] 에러 모음. (0) | 2020.03.17 |
스프링부트] 서버 포트 바꾸기 (0) | 2020.03.16 |