Notice
Recent Posts
Recent Comments
Link
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Tags
more
Archives
Today
Total
관리 메뉴

채채

compileClasspath vs runtimeClasspath 본문

spring boot

compileClasspath vs runtimeClasspath

HChaeEun 2024. 1. 6. 20:48

figma 정리본

compileClasspath과 runtimeClasspath의 차이점을 알아보자.

먼저 둘의 이름을 보면 대략 compileClasspath는 compile할 때 필요한 class들의 path이고,

runtimeClasspath는 runtime에 필요한 class들의 path인가? 라는 생각이 들었다.

 

그러나 classpath가 무엇인지 개념적인 설명을 깊이 할 수 없었다.

1. classPath란?

우리가 java로 코드를 작성한 .java파일(소스 코드)을 compile하면 .class파일(바이트 코드의 실행 파일)이 생성된다.

만약 우리가 program.java파일의 소스코드 맨 윗단에 외부 패키지를 import했다고 하자.

그럼 자바 컴파일러는 해당 패키지를 찾으려고 import한 경로를 따라 찾을 것이다.

이때 사용된 경로가 classPath이다.

 

classPath란, JVM이나 자바 컴파일러가 패키지나 클래스를 찾기위한 기준이 되는 경로이다.

 

2. compileClasspath? runtimeClasspath?

 

Java Library Plugin Configuration

먼저 초록색은 spring dependency 선언 시 많이 사용되었던 것인데, 사용자가 의존성을 작성할 때 사용된다.

dependencies { 
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    runtimeOnly 'org.postgresql:postgresql'
}

 

이어서 우리가 알고자 하는 파란색은 초록색의 구성 요소들의 사용을 위해 내부에서 사용되는 것이다. 

compileClasspath는 예측하던대로 compile 할 때 필요한 classpath이다.

이는 compile할 때만 사용되므로 build 결과물에 포함되지 않는다.

따라서 compile에 필요한 라이브러리만 `compileOnly`를 통해 구분해서 선언한다면 build 결과물의 크기를 줄일 수 있다.

 

compileClasspath를 확인하기 위해서는 아래의 명령어를 터미널에 입력하면 된다.

./gradlew dependencies --configuration compileClasspath

 

runtimeClasspath는 runtime 때 필요한 classpath이다.

이는 build 결과물에 포함되지만, 마찬가지로 `runtimeOnly`로 runtime에 필요한 라이브러리만 선언한다면 compile 속도를 향상시킬 수 있다.

 

아래의 명령어를 통해 runtimeClasspath를 확인할 수 있다.

./gradlew dependencies --configuration runtimeClasspath

 

 

참고)

 

Gradle의 라이브러리 의존성 옵션 정리

익숙함 문득 웹 프로젝트 관련 내용들을 정리해나가면서, gradle 파일을 보니까 다음과 같은 부분이 눈에 들어왔다. dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'or

twinparadox.tistory.com

 

자바 클래스패스(classpath)란?

클래스패스란(Class Path)란??클래스패스란 말 그대로 클래스를 찾기위한 경로이다. 자바에서 클래스패스의 의미도 똑같다. 즉, JVM이 프로그램을 실행할 때, 클래스파일을 찾는 데 기준이 되는 파

effectivesquid.tistory.com

 

[Java] Gradle Dependency Configurations

compileClasspath 컴파일 시에 필요한 class path

da-nyee.github.io

 

[Spring] Gradle - runtimeOnly, compileOnly, implementation의 차이

Goals compileClasspath vs runtimeClasspath compileOnly vs runtimeOnly vs implementation compileClasspath vs runtimeClasspath compileClasspath와 runtimeClasspath는 Gradle에서 프로젝트의 의존성 관리를 위해 사용되는 두 가지 중요한

bnzn2426.tistory.com

 

컴파일타임(Compiletime) & 런타임(Runtime)

컴파일타임(Compiletime)과 런타임(Runtime) 개발자가 작성한 소스 코드를 기계 코드로 컴파일 해야 프로그램을 실행 할 수 있다. 이 컴파일 프로세스를 컴파일타임 이라고 한다. 컴파일 된 프로그램

zoiworld.tistory.com