๐ง java ํ๋ฌ๊ทธ์ธ
์๋ฐ ํ๋ฌ๊ทธ์ธ์ ์๋ฐ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋น๋ํ๋๋ฐ ํ์ํ ์ปดํ์ผ, ํ ์คํธ ๋ฐ ์ฌ๋ฌ ๊ธฐ๋ฅ๋ค์ ํ๋ก์ ํธ์ ์ถ๊ฐํฉ๋๋ค.
์ด๋ ๋ง์ ๋ค๋ฅธ JVM ์ธ์ด ํ๋ฌ๊ทธ์ธ์ ๊ธฐ๋ฐ์ด ๋๋ ํ๋ฌ๊ทธ์ธ์ ๋๋ค.
ํด๋น ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ๊ธฐ ์ํด์๋ build.gradle์ ๋ค์๊ณผ ๊ฐ์ด ์์ฑํ ์ ์์ต๋๋ค.
plugins {
id 'java'
}
๐ง java ํ๋ฌ๊ทธ์ธ์์ ์ ๊ณตํ๋ Task
๋ช๊ฐ๋ง ์ดํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
๋์ฑ ์์ธํ ํ์ธํ๊ณ ์ถ๋ค๋ฉด ๋ค์ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์.
๐ฑ compileJava
Depends on: ์ปดํ์ผ classpath์ ์ํฅ์ ์ฃผ๋ ๋ชจ๋ ์์
ํด๋น ์์ ์ ํ๋ก๋์ ์๋ฐ ์ฝ๋๋ฅผ JDK ์ปดํ์ผ๋ฌ๋ฅผ ์ด์ฉํ์ฌ ์ปดํ์ผํ๋ ์์ ์ ๋๋ค.
ํด๋น ์์ ์ ์คํํ๋ฉด ๋ค์๊ณผ ๊ฐ์์ง๋๋ค.
๐ฑ processResources
ํ๋ก๋์ ์ resources๋ฅผ build ๋๋ ํ ๋ฆฌ ํ์์ ํ๋ก๋์ ์ resources ๋๋ญํ ๋ฆฌ์ ๋ณต์ฌํฉ๋๋ค.
์ด๋ฅผ ์ํํ๋ฉด ๋ค์๊ณผ ๊ฐ์์ง๋๋ค.
๐ฑ classes
Depends on: [compileJava], [processResources]
์ด๋ ๋ค๋ฅธ ์์ ์๋ง ์์กดํ๋(depens on) ์ง๊ณ(aggregate) ์์ ์ ๋๋ค.
๋ค๋ฅธ ํ๋ฌ๊ทธ์ธ๋ค์ ์ปดํ์ผ ์์ ์ ์ถ๊ฐ๋ก ์ฐ๊ฒฐํ ์ ์์ต๋๋ค.
ํด๋น ์์ ์ ์ํํ ๊ฒฐ๊ณผ๋, compileJava์ processResources๋ฅผ ์ํํ ๊ฒฐ๊ณผ์ ๋์ผํฉ๋๋ค.
๐ฑ compileTestJava
Depends on: [classes], testCompileClasspath์ ๊ด๋ จ๋ ๋ชจ๋ ์์ (tatk)
JDK ์ปดํ์ผ๋ฌ๋ฅผ ์ฌ์ฉํ์ฌ ํ ์คํธ์ฝ๋๋ฅผ ์ปดํ์ผํฉ๋๋ค.
์คํํ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
๐ฑ processTestResources
test resources๋ฅผ build ๋๋ ํ ๋ฆฌ ํ์์ ํ ์คํธ์ resources ๋๋ญํ ๋ฆฌ์ ๋ณต์ฌํฉ๋๋ค.
์ด๋ฅผ ์ํํ๋ฉด ๋ค์๊ณผ ๊ฐ์์ง๋๋ค.
๐ฑ testClasses
Depends on: [compileJava], [processTestResources]
classes์ ๋น์ทํ๊ฒ ํด๋น ์์ ์ ์ํํ ๊ฒฐ๊ณผ๋, compileJava์ processTestResources๋ฅผ ์ํํ ๊ฒฐ๊ณผ์ ๋์ผํฉ๋๋ค.
๐ฑ jar
Depends on: [classes]
main source set ์ ์ฒจ๋ถ๋ classes์ resources๋ฅผ ๊ธฐ๋ฐ์ผ๋ก JAR ํ์ผ์ ์์ฑํฉ๋๋ค.
์คํ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
๐ฑ javadoc
Depends on: [classes]
Javadoc์ ์ฌ์ฉํ์ฌ ํ๋ก๋์ ์๋ฐ ์ฝ๋์ ๋ํ API ๋ฌธ์๋ฅผ ์์ฑํฉ๋๋ค.
์คํ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
๐ฑ test
Depends on: [testClasses], test runtile classpath์ ๊ด๋ จ๋ ๋ชจ๋ ์์ (task)๋ค
JUnit ๋ฑ์ ์ฌ์ฉํ์ฌ ๋จ์ ํ ์คํธ๋ฅผ ์คํํฉ๋๋ค.
๐ฑ clean
ํ๋ก์ ํธ์ build ๋๋ ํ ๋ฆฌ๋ฅผ ์ญ์ ํฉ๋๋ค
๐ฑ cleanTaskName
์ง์ ํ ์์ ์์ ๋ง๋ค ํ์ผ์ ์ญ์ ํฉ๋๋ค.
์๋ฅผ ๋ค์ด cleanJar์ jar task์ ์ํด ์์ฑ๋ JAR ํ์ผ์ ์ญ์ ํฉ๋๋ค.
cleanTest๋ test task์ ์ํด ์์ฑ๋ ํ ์คํธ ๊ฒฐ๊ณผ๋ฅผ ์ญ์ ํฉ๋๋ค.
๐ฑ assemble
Depends on: [jar], archives configuration์ ์ฒจ๋ถ๋ ์ํฐํฉํธ๋ฅผ ์์ฑํ๋ ๋ค๋ฅธ ๋ชจ๋ ์์ ๋ค
ํ๋ก์ ํธ์ ๋ชจ๋ archives๋ฅผ ์กฐ๋ฆฝํฉ๋๋ค.
(๋ญ์ง๋ ์ ๋ ์ ๋ชจ๋ฅด๊ฒ ์ด์ฉ...ใ ใ )
๐ฑ check
Depends on: [test]
ํ์คํธ ์คํ๊ณผ ๊ฐ์ด ๊ฒ์ฆ ์์ ์ ๋ชจ๋ ์ํํ๋ ์ก์ ์ ๋๋ค.
์ผ๋ถ ํ๋ฌ๊ทธ์ธ์์๋ [check] ์์ ์ ๊ทธ๋ค๋ง์ ๊ฒ์ฆ ์์ ์ ์ถ๊ฐํ ์ ์์ต๋๋ค.
๐ฑ build
Depends on: [check], [assemble]
ํ๋ก์ ํธ๋ฅผ ์์ ํ ๋น๋ํ๋ ์์ ์ ๋๋ค.
task๋ค์ ๊ด๊ณ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
๐ง Dependency Configuration
์ด๋ฒ์๋ ์๋ฐ ํ๋ฌ๊ทธ์ธ์์ ์ ๊ณตํ๋ ์ฌ๋ฌ configuration๋ค์ ์ดํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
compilejava๋ test์ ๊ฐ์ ์์ (task)๋ค์ ์ด๋ฌํ configuration๋ค ์ค ํ๋ ์ด์์ ์ฌ์ฉํ์ฌ ํด๋น ํ์ผ์ ๊ฐ์ ธ์ ์ฌ์ฉํฉ๋๋ค.
์๋ฅผ ๋ค์ด ์ด๋ฌํ ์์กด์ฑ๋ค์ ์ปดํ์ผ ํน์ ๋ฐํ์ classpath์ ๋ฐฐ์นํ ์ ์์ต๋๋ค.
๐ฑ implementation
์ค์ง ๋ด๋ถ์์๋ง ์ฌ์ฉํ๊ณ ์ธ๋ถ๋ก๋ ๋ ธ์ถ๋์ง ์์ ์์กด์ฑ์ ์ ์ธํ๋๋ฐ ์ฌ์ฉํฉ๋๋ค.
๐ฑ compileOnly
์ปดํ์ผ ์์๋ ํ์ํ์ง๋ง, ๋ฐํ์ ์์๋ ํ์ํ์ง ์๋ ์์กด์ฑ์ ์ ์ธํ๋๋ฐ ์ฌ์ฉํฉ๋๋ค.
๐ฑ runtimeOnly
์ปดํ์ผ ์์๋ ํ์์์ง๋ง, ๋ฐํ์์๋ ํ์ํ ์์กด์ฑ์ ์ ์ธํ๋๋ฐ ์ฌ์ฉํฉ๋๋ค.
๐ฑ testImplementation
ํ ์คํธ๋ฅผ ์คํํ๋๋ฐ ํ์ํ ์์กด์ฑ์ ์ ์ธํฉ๋๋ค.
์ด๋ implementation์ ์์ํฉ๋๋ค. ์ฆ implementation์ผ๋ก ์ ์ธ๋ ์์กด์ฑ๋ค๋ testImplementation์ ํฌํจ๋ฉ๋๋ค.
์ ๋ง ํฌํจ๋๋์ง ํ์ธํด ๋ณด๊ฒ ์ต๋๋ค.
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation 'junit:junit:4.12'
implementation 'org.apache.commons:commons-lang3:3.5'
}
// ์ถ๋ ฅ์ ์ํ ๋ถ๋ถ
configurations {
println "implementation: "
prettyPrint(implementation.getAllDependencies())
println ""
println "testImplementation: "
prettyPrint(testImplementation.getAllDependencies())
}
private void prettyPrint(DependencySet dependencies) {
dependencies.forEach(it -> println(" "+it.group + ":" + it.name + ":" + it.version))
}
// ์ถ๋ ฅ์ ์ํ ๋ถ๋ถ
๋ค์๊ณผ ๊ฐ์ด implementation์ผ๋ก ์ค์ ๋ ์์กด์ฑ์ด testImplementation์ ํฌํจ๋ ๊ฒ์ ์ ์ ์์ต๋๋ค.
๐ฑ testCompileOnly
ํ ์คํธ์ฝ๋๋ฅผ ์ปดํ์ผ ํ ๋์๋ ํ์ํ์ง๋ง, ๋ฐํ์ ์์๋ ํ์ํ์ง ์์ ์์กด์ฑ์ ์ ์ธํฉ๋๋ค.
(์ด๋ compileOnly๋ฅผ ์์ํ์ง ์์ต๋๋ค.)
๐ฑ testRuntimeOnly
ํ ์คํธ์ฝ๋ ๋ฐํ์ ์์๋ ํ์ํ์ง๋ง, ์ปดํ์ผ ์์๋ ํ์ํ์ง ์์ ์์กด์ฑ์ ์ ์ธํ๋๋ฐ ์ฌ์ฉํฉ๋๋ค.
์ด๋ runtimeOnly์ ์์ํฉ๋๋ค. ์ฆ runtimeOnly์ผ๋ก ์ ์ธ๋ ์์กด์ฑ๋ค๋ testRuntimeOnly์ ํฌํจ๋ฉ๋๋ค.
๐ฑ compileClasspath
compileClasspath์ ์ถ๊ฐ๋ ์์กด์ฑ๋ค์ ์ ์ธํ๋๋ฐ ์ฌ์ฉํฉ๋๋ค.
์ด๋ implementaion๊ณผ compileOnly๋ฅผ ์์ํ๊ธฐ ๋๋ฌธ์, implementation์ผ๋ก ์ค์ ๋ ์์กด์ฑ๊ณผ compileOnly ์์กด์ฑ๋ค๋ก ์ ์ธ๋ ์์๋ค์ ํฌํจํฉ๋๋ค.
์๋ฅผ ๋ค์ด ๋ค์๊ณผ ๊ฐ์ด ์ฝ๋๋ฅผ ์์ฑํ๋ฉด,
dependencies {
implementation 'junit:junit:4.12'
compileOnly 'org.apache.commons:commons-lang3:3.5'
}
compileClasspath๋ ๋ค์๊ณผ ๊ฐ์์ง๋๋ค.
๐ฑ runtimeClasspath
runtimeClasspath์ ์ถ๊ฐ๋ ์์กด์ฑ๋ค์ ์ ์ธํ๋๋ฐ ์ฌ์ฉํฉ๋๋ค.
์ด๋ implementaion๊ณผ runtimeOnly๋ฅผ ์์ํ๊ธฐ ๋๋ฌธ์, implementation์ผ๋ก ์ค์ ๋ ์์กด์ฑ๊ณผ runtimeOnly ์์กด์ฑ๋ค๋ก ์ ์ธ๋ ์์๋ค์ ํฌํจํฉ๋๋ค.
๐ฑ testCompileClasspath
testCompileClasspath์ ์ถ๊ฐ๋ ์์กด์ฑ๋ค์ ์ ์ธํ๋๋ฐ ์ฌ์ฉํฉ๋๋ค.
์ด๋ testImplementaion๊ณผ testCompileOnly๋ฅผ ์์ํ๊ธฐ ๋๋ฌธ์, testImplementaion์ผ๋ก ์ค์ ๋ ์์กด์ฑ๊ณผ testCompileOnly ์์กด์ฑ๋ค๋ก ์ ์ธ๋ ์์๋ค์ ํฌํจํฉ๋๋ค.
์ด๋ testImplementation์ implementation์ ์์ํ๊ธฐ ๋๋ฌธ์, implementation์ผ๋ก ์ ์ธ๋ ์์กด์ฑ๋ค ์ญ์๋ ์ด๊ณณ์ ํฌํจ๋ฉ๋๋ค.
์๋ฅผ ๋ค์ด ๋ค์๊ณผ ๊ฐ์ด ์ฝ๋๋ฅผ ์์ฑํ๋ฉด
dependencies {
implementation 'junit:junit:4.12'
testCompileOnly 'com.google.guava:guava:28.1-jre'
testImplementation 'org.apache.commons:commons-lang3:3.5'
}
testCompileClasspath๋ ๋ค์๊ณผ ๊ฐ์์ง๋๋ค.
๐ฑ testRuntimeClasspath
testRuntimeClasspath์ ์ถ๊ฐ๋ ์์กด์ฑ๋ค์ ์ ์ธํ๋๋ฐ ์ฌ์ฉํฉ๋๋ค.
์ด๋ testImplementaion๊ณผ testRuntimeOnly๋ฅผ ์์ํ๊ธฐ ๋๋ฌธ์, testImplementaion์ผ๋ก ์ค์ ๋ ์์กด์ฑ๊ณผ testRuntimeOnly ์์กด์ฑ๋ค๋ก ์ ์ธ๋ ์์๋ค์ ํฌํจํฉ๋๋ค.
๐ฑ annotationProcessor
์ปดํ์ผ ์์ ์ฌ์ฉ๋ Annotation Processor์ ๋ํ ์์กด์ฑ์ ์ ์ธํ๋๋ฐ ์ฌ์ฉํฉ๋๋ค.
์ด๋ฌํ Configuration๋ค์ ๊ด๊ณ๋ ๋ค์ ๊ธ์์ ์๋ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ๋ฌ๊ทธ์ธ์ด ์ถ๊ฐ์ ์ผ๋ก ์ ๊ณตํ๋ api configuration๊น์ง ์ดํด๋ณธ ํ์ ์ ๋ฆฌํ๋๋ก ํ๊ฒ ์ต๋๋ค.
๐ Reference
https://docs.gradle.org/current/userguide/java_plugin.html#java_plugin
The Java Plugin
If a dependent project has changed in an ABI-compatible way (only its private API has changed), then Java compilation tasks will be up-to-date. This means that if project A depends on project B and a class in B is changed in an ABI-compatible way (typicall
docs.gradle.org
'๐ Gradle' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Gradle] api์ implementation์ ์ฐจ์ด (feat. java-libraly ํ๋ฌ๊ทธ์ธ) (0) | 2023.04.16 |
---|---|
[Gradle] Dependency Configuration์ด๋? (0) | 2023.04.15 |
[Gradle] ์์กด์ฑ ๊ด๋ฆฌ(Dependency management)๋? (0) | 2023.04.15 |
[Gradle] Gradle Wrapper(gradlew์ gradle.bat)์ settings.gradle (0) | 2023.04.14 |
[Gradle] Gradle์ ๊ตฌ์ฑ์์(Project, Task, Plugin)์ ์์ํด๋ณด๊ธฐ (0) | 2023.04.14 |