Java 프로젝트를 만들 때 간혹 추가한 외부 라이브러리가 classpath에 제대로 등록되지 않는 경우가 있다. 대게 문법 오류로 인한 문제겠다. 이럴 땐 제대로 등록된 라이브러리 목록을 봐가며 점검을 할 필요가 있다.
아래엔 Gradle Task를 이용해 등록된 라이브러리 Jar 목록을 출력하는 방법을 소개한다. Gradle 버전에 따라 문법이 다를 수 있으니 주의할 것!
...
configurations {
testImplementation {
canBeResolved(true)
}
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
}
tasks.register('list') {
dependsOn configurations.testImplementation
doLast {
println "classpath :\n${configurations.testImplementation.collect { it.name }.join("\n")}"
}
}
gradle에서 classpath는 dependency 유형(implementation, complie, ... 등)에 따라 달리 적용된다. 따라서 classpath 출력도 dependency 유형 별로 따로 해야한다. task를 등록하기 앞서 configuration에서 dependency 유형 옵션 중 canBeResolved를 true로 바꾸어줘야한다. 그럼 task를 등록해보자. 등록된 라이브러리의 이름을 읽어서 한줄씩 출력하는 코드다.
지금은 testImplementation로 한건데 실제 runtime 환경 기준으로 보고 싶으면 이걸 implementation으로 이름만 바꾸면 된다.
./gradlew task list
> Task :list
classpath :
junit-platform-commons-1.8.1.jar
junit-jupiter-api-5.8.1.jar
opentest4j-1.2.0.jar
정의한 task를 실행하면 위에처럼 등록한 라이브러리 내에 있는 jar 파일들을 목록이 출력된다!
'JAVA' 카테고리의 다른 글
[Java DataEngineering] Parquet 파일 쓰고 읽는 코드 정리 Write & Read (0) | 2022.11.25 |
---|---|
Netty 기반 경량 Http Server 구성 ( with Gradle ) (1) | 2022.09.25 |
JAVA Installation On Linux (0) | 2022.09.02 |
About JAVA Platform (0) | 2022.09.02 |
Spring boot 프로젝트 도커 이미징 (0) | 2022.09.02 |