๐ง ์๋ก
์ด์ ๊ธ์์ ์์กด์ฑ ๊ด๋ฆฌ์ ๋ํด์ ๊ฐ๋ตํ๊ฒ ์์๋ณด์์ต๋๋ค.
์ด๋ฒ์๋ ์์กด์ฑ์ ๋ํด์ ์กฐ๊ธ ์์ธํ ์์๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
์์กด์ฑ์ ์ฌ์ฉํ๊ธฐ ์ ์ dependency configuration์ด๋ผ๋ ๊ฐ๋ ์ ๋ํด์ ์์๋ณด๊ฒ ์ต๋๋ค.
๐ง Dependency Configuration
Gradle ๊ธฐ๋ฐ์ ํ๋ก์ ํธ์์ ์ ์ธ๋๋ ๋ชจ๋ ์์กด์ฑ๋ค์ ํด๋น ์์กด์ฑ์ด ์ฌ์ฉ๋์ด์ง๋ ํน์ ํ scope๊ฐ ์์ต๋๋ค.
์๋ฅผ ๋ค์ด ์ด๋ค ์์กด์ฑ์ ์์ค ์ฝ๋๋ฅผ ์ปดํ์ผํ๋๋ฐ ์ฌ์ฉ๋์ด์ง๊ณ , ์ด๋ค ์์กด์ฑ์ ๋ฐํ์์๋ง ์ฌ์ฉ๋์ด์ง๋๋ค.
ํ ์คํธ ํ๊ฒฝ์์๋ง ์ฌ์ฉ๋์ด์ผ ํ๋ ์์กด์ฑ๋ค๋ ์กด์ฌํฉ๋๋ค.
Gradle์์๋ ์์กด์ฑ์ด ์ฌ์ฉ๋๋ scope๋ฅผ configuration์ ํตํด ๋ช ์ํฉ๋๋ค.
๋ชจ๋ configuration์ ๊ณ ์ ํ ์ด๋ฆ์ผ๋ก ์๋ณํ ์ ์์ต๋๋ค.
๐ฑ Plugin๊ณผ configuration
๋ง์ Gradle์ ํ๋ฌ๊ทธ์ธ(plugin)๋ค์ ํด๋น ํ๋ฌ๊ทธ์ธ์์ ๋ฏธ๋ฆฌ ์ ์ํ configuration๋ค์ ํ๋ก์ ํธ์ ์ถ๊ฐํฉ๋๋ค.
์๋ฅผ ๋ค์ด, ์๋ฐ ํ๋ฌ๊ทธ์ธ์ ์ฝ๋ ์ปดํ์ผ, ํ ์คํธ ์คํ ๋ฑ์ ํ์ํ ๋ค์ํ ํด๋์คํจ์ค(classpath)๋ฅผ ๋ํ๋ด๊ธฐ ์ํ configuration๋ค์ ์ถ๊ฐํฉ๋๋ค.
๋ค์์ configuration๋ค์ด ํน์ ํ ๋ชฉ์ ์ ์ํด ์ ์ธ๋ ์์กด์ฑ์ ์ฌ์ฉํ๋ ๊ทธ๋ฆผ์ ๋๋ค.
์์ค ์ฝ๋๋ฅผ ์ปดํ์ผํ๋ ๊ฒฝ์ฐ์๋ implementation์ด๋ผ๋ configuration์ ์ฌ์ฉํ๋ฉฐ,
ํ ์คํธ๋ฅผ ์คํํ๋ ๊ฒฝ์ฐ์๋ testRuntime์ด๋ผ๋ configuration์ ์ฌ์ฉํ๋ ๊ฒ์ ์ ์ ์์ต๋๋ค.
์ด์ ๋ํ ๋ ์์ธํ ์ค๋ช ์ java ํ๋ฌ๊ทธ์ธ์ ์ดํด๋ณด๋ ๊ธ์์ ๋ค๋ฃจ๋๋ก ํ๊ฒ ์ต๋๋ค.
๋ ๋ง์ configuration์ ์ฌ์ฉ ์์๋ resolution result APIs๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์.
๐ฑ configuration์ ์์(inheritance)๊ณผ ํฉ์ฑ(composition)
Configuration์ ๋ค๋ฅธ configuration์ ํ์ฅ(extends)ํจ์ผ๋ก์จ ์์ ๊ณ์ธต์ ํ์ฑํ ์ ์์ต๋๋ค.
์์ configuration์ ๋ถ๋ชจ configuration๋ค์ด ์ ์ธํ ๋ชจ๋ ์์กด์ฑ๋ค์ ๋ฌผ๋ ค๋ฐ์ต๋๋ค.
์๋ฐ ํ๋ฌ๊ทธ์ธ์ ์์๋ก ์ดํด๋ณด๋ฉด, testImplementation์ implementation์ ์์ํฉ๋๋ค.
ํ ์คํธ ์ฝ๋๋ฅผ ์ปดํ์ผํ๊ธฐ ์ํด์๋, ํ ์คํธํ๋ ค๋ ์์ค ์ฝ๋์ ์์กด์ฑ ๋ฟ๋ง ์๋๋ผ, ํ ์คํธ ํด๋์ค๋ฅผ ์์ฑํ๋ ๋ฐ ํ์ํ ์์กด์ฑ๊น์ง ๋ชจ๋ ํ์ํ๋ฐ์, ์ด๋ฅผ ์ํด testImplementation์ด implementation์ ์์ํ๋๋ก ํ์์ต๋๋ค.
testImplementation์ ์ ์ธ๋ ์์กด์ฑ๋ค์ ํ ์คํธ๋ฅผ ์ํ classpath์ธ testCompileClasspath๊ณผ testRuntimeClasspath์ ์ถ๊ฐํ๋๋ฐ์, testImplementation์ implementation์ ์์ํ๊ธฐ ๋๋ฌธ์ implementaion์ ์ ์ธ๋ ์์กด์ฑ๋ค ์ญ์ testCompileClasspath๊ณผ testRuntimeClasspath์ ์ถ๊ฐ๋ฉ๋๋ค.
์๋ ๊ทธ๋ฆผ์ ํ๋์ ์์๋ฅผ ๋ํ๋ ๋๋ค.
implementation์ผ๋ก ์ค์ ๋ Guava๋ ํ๋ก๋์ ํ๊ฒฝ์์ ์คํ๋ ๋์๋ ํ์ํ์ง๋ง, ํ ์คํธ์์๋ ํ์ํ๊ธฐ ๋๋ฌธ์ compileClasspath, runtimeClasspath, testCompileClasspath, testRuntimeClassPath์ ๋ชจ๋ ์ถ๊ฐ๋ฉ๋๋ค.
๊ทธ๋ฌ๋ testImplementation์ผ๋ก ์ ์ธ๋ JUnit์ ์ค์ง testCompileClasspath, testRuntimeClassPath์๋ง ์ถ๊ฐ๋๋ฏ๋ก, ํ๋ก๋์ ํ๊ฒฝ์์๋ ์ด๋ฅผ ์์กดํ์ง ์๊ฒ ๋ฉ๋๋ค.
๐ Configuration ์์ํด๋ณด๊ธฐ
Configuration์ ์์์ ๋ด๋ถ์ ์ผ๋ก Configuration์ extendsFrom์ด๋ผ๋ ๋ฉ์๋๋ฅผ ํธ์ถํจ์ผ๋ก์จ ์ด๋ฃจ์ด์ง๋๋ค.
์ด๋ฅผ ์ง์ ์ฌ์ฉํ๋ ์์๋ฅผ ์ดํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
smoke test๋ฅผ ์์ฑํ๋ ค๋ ์ํฉ์ ๊ฐ์ ํด ๋ณด๊ฒ ์ต๋๋ค.
somke test๋ HTTP ํธ์ถ์ ํตํด endpoint๋ฅผ ๊ฒ์ฆํฉ๋๋ค.
๊ธฐ๋ณธ ํ ์คํธ ํ๋ ์์ํฌ๋ก๋ ์ด๋ฏธ JUnit์ ์ฌ์ฉํ๊ณ ์๋ค๊ณ ํ๊ฒ ์ต๋๋ค.
์ด์ testImplementation์ ์์ํ๋ smokeTest๋ผ๋ ์ด๋ฆ์ ์๋ก์ด configuration์ ์ ์ํ๋๋ก ํ๊ฒ ์ต๋๋ค.
์ด๋ฅผ ํตํด smokeTest์์๋ testImplementation์์ ์ ์ธ๋ ์์กด์ฑ๋ค(JUnit)์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
configurations {
smokeTest.extendsFrom testImplementation
}
dependencies {
testImplementation 'junit:junit:4.13' // smokeTest ์์๋ ์ฌ์ฉํ ์ ์๋ค.
smokeTest 'org.apache.httpcomponents:httpclient:4.5.5'
}
๐ง Project dependencies
์ํํธ์จ์ด๋ ์ข ์ข ์ํํธ์จ์ด ๊ตฌ์ฑ์์๋ค์ ๋ชจ๋๋ก ๋ถํ ํ์ฌ ์ ์ง๋ณด์์ฑ์ ๊ฐ์ ํ๊ณ ๊ฐ๊ฒฐํฉ์ ๋ฐฉ์งํฉ๋๋ค.
๋ชจ๋๋ค์ ๋์ผํ ํ๋ก์ ํธ ๋ด์์ ์ฝ๋๋ฅผ ์ฌ์ฌ์ฉํ๊ธฐ ์ํด ์๋ก๊ฐ์ ์์กด์ฑ์ ์ ์ํ ์ ์์ต๋๋ค.
Gradle์ ๋ชจ๋๊ฐ์ ์์กด์ฑ์ ๋ชจ๋ธ๋งํ ์ ์์ต๋๋ค.
์ด๋ฌํ ์์กด์ฑ๋ค์ project dependencies๋ผ๊ณ ๋ถ๋ฆฌ๋๋ฐ, ์ด๋ ๊ฐ๊ฐ์ ๋ชจ๋์ด Gradle project๋ก ํํ๋๊ธฐ ๋๋ฌธ์ ๋๋ค.
์์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
dependencies {
implementation project(':shared')
}
์ด๋ฅผ ํตํด ํด๋น build.gradle์ ์ฌ์ฉํ๋ project๋ shared๋ผ๋ ํ๋ก์ ํธ์ ๋ํ์ฌ ์์กด์ฑ์ ๊ฐ์ง๊ฒ๋ฉ๋๋ค.
๋ฐํ์์์, ๋น๋๋ ์์กด์ฑ์ด ์ฌ๋ฐ๋ฅธ ์์๋ก ๊ตฌ์ฑ๋๊ณ classpath์ ์ถ๊ฐ๋๋๋ก ์๋์ ์ผ๋ก ๋ณด์ฅํฉ๋๋ค.
๋ฉํฐ๋ชจ๋์ ๋ํ ์์ธํ ๋ด์ฉ์ Authoring Multi-Project Builds๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์.
์ด์ธ์๋ ๋ค์ํ ์ข ๋ฅ์ dependency๋ค์ด ์๋๋ฐ, ์ด๋ค์ ๋ํ ๋ด์ฉ์ Different kinds of dependencies๋ฅผ ํ์ธํด์ฃผ์ธ์.
๐ Reference
https://docs.gradle.org/current/userguide/declaring_dependencies.html#sec:dependency-types
Declaring dependencies
Whenever Gradle tries to resolve a module from a Maven or Ivy repository, it looks for a metadata file and the default artifact file, a JAR. The build fails if none of these artifact files can be resolved. Under certain conditions, you might want to tweak
docs.gradle.org
'๐ Gradle' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Gradle] api์ implementation์ ์ฐจ์ด (feat. java-libraly ํ๋ฌ๊ทธ์ธ) (0) | 2023.04.16 |
---|---|
[Gradle] ์๋ฐ ํ๋ฌ๊ทธ์ธ (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 |