Gradle dependencies

BK·2024년 4월 30일
0

Spring

목록 보기
1/6


코끼리

Gradle dependencies - scope & keyword

  • Gradle scope
    • compile : default scope
    • provided : 최종 build결과에 포함되지 않음
    • runtime : compile시 포함되지 않으며, 실행 시 필요한 경우에만 사용
    • test : 테스트시에만 포함됨
  • Gradle dependency keyword
    • implementation : 전 범위에 module이 적용
      • 하나의 module 수정에도 모든 module을 재빌드하는 compile을 대체할 수 있으며, compile은 deprecated
      • 유사하게 api도 있으며, api와 implementation의 차이는 의존 모듈 수정 시 해당 모듈 뿐만 아니라 해당 모듈이 의존하는 모듈 또한 함께 재빌드(api)되는 것이다.
    • testImplementation : test시 module이 적용
      • testCompileOnly, testRunTimeOnly
    • debugImplementation : 디버그 모드에서 module이 적용
    • compileOnly : 컴파일시에만(runtime 제외) module이 적용 - lombok
    • runtimeOnly : runtime시에만 module이 적용 - db connection

Runtime vs. Compile

  • Java project를 build하고 실행에 있어 두가지 classpath가 사용된다. Compile classpath와 Runtime classpath이다.
    • Compile classpath는 source code를 byte code로 컴파일 할 때 필요하며
    • Runtime classpath는 byte code를 실제로 실행할 때 필요하다
  • 이로 인해 gradle은 compileOnly, runtimeOnly를 구분하며, 둘 다 사용하는 implementation이 있다.

출처-https://tomgregory.com/gradle/gradle-implementation-vs-compile-dependencies/

0개의 댓글