Build Tools
๋น๋ ๋๊ตฌ๋, ๋น๋ ์๋ํ๋ฅผ ํตํด ์คํ๊ฐ๋ฅํ ํ๋ก๊ทธ๋จ(์ ํ๋ฆฌ์ผ์ด์ )์ ๋ง๋ค์ด ์ฃผ๋ ํ๋ก๊ทธ๋จ์ ๋งํ๋ค.
๋น๋ : ์์ค์ฝ๋ ํ์ผ๋ค์ ์ปดํจํฐ์์ ์คํํ ์ ์๋ ์ํํธ์จ์ด๋ก ๋ณํํ๋ ์ผ๋ จ์ ๊ณผ์ ์ผ๋ก, compile, test, deploy ๋ฑ ๋ชจ๋ ๊ณผ์ ์ ์งํฉ
๋ํ์ ์ธ ๋น๋ ๋๊ตฌ ์ข ๋ฅ์๋ Ant, Maven, Gradle์ด ์๋ค.
Ant
Ant์ ๊ฐ์ฅ ํฐ ์ฅ์ ์ ๊ฐ๋ฐ์๊ฐ ์์ ๋กญ๊ฒ ๋น๋ ๋จ์(target)์ ์ง์ ํ๊ณ ๋น๋ ๋จ์๊ฐ์ ์์กด๊ด๊ณ๋ฅผ ์์ ๋กญ๊ฒ ์ค์ ํ ์ ์๋ค๋ ๊ฒ์ด๋ค. ํ์ง๋ง ์์ ๋๊ฐ ๋๋ค๋ ๊ฒ์ ์ ํ์ฉํ ๊ฒฝ์ฐ ์ข์ ๋๊ตฌ๊ฐ ๋ ์ ์์ง๋ง ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ ์ ๋ฌผ๋จ์ง๋ก ์ ๋ฝํ ๊ฐ๋ฅ์ฑ์ด ์๋ค.
XML ๊ธฐ๋ฐ ๋น๋ ์คํฌ๋ฆฝํธ(
build.xml
)๊ท์น์ด ์์
์ ์ฐจ์
์๋ช ์ฃผ๊ธฐ๋ฅผ ๊ฐ์ง ์์ ๊ฐ๊ฐ์ target์ ๋ํ ์์กด์ฑ์ ์ง์ ์ ์ ํด์ค์ผํ๋ค.
๋จ์
์ ์ฐ์ฑ์ด ๋์ง๋ง, ํ๋ก์ ํธ๊ฐ ๋ณต์กํด์ง๋ ๊ฒฝ์ฐ build ๊ณผ์ ์ ์ดํด๊ฐ ์ด๋ ต๋ค
XML, Remote Repository๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋ค
์คํฌ๋ฆฝํธ์ ์ฌ์ฌ์ฉ์ด ์ด๋ ต๋ค.
Apache Maven์ ์๋ฐ์ฉ ํ๋ก์ ํธ ๊ด๋ฆฌ๋๊ตฌ๋ก Apache Ant์ ๋์์ผ๋ก ๋ง๋ค์ด์ง
ํ๋ก์ ํธ์ ์ ์ฒด์ ์ธ ๋ผ์ดํ ์ฌ์ดํด์ ๊ด๋ฆฌํ๋ ๋๊ตฌ
pom.xml
ํ์ผ์ ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ ์ํด ๋๋ฉด, ํด๋น ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์๋ํ๋ ์์กด์ฑ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค๊น์ง ๊ด๋ฆฌํ์ฌ, ์๋์ผ๋ก ๋ค์ด๋ก๋ ๋ฐ์์ค๊ฐ๋จํ ์ค์ ์ ํตํ ๋ฐฐํฌ ๊ด๋ฆฌ๊ฐ ๊ฐ๋ฅ
๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์๋ก ์ข ์๋์ด์์ ๊ฒฝ์ฐ XML์ด ๋ณต์กํด์ง๋ฉฐ, ๊ณ์ธต์ ์ธ ๋ฐ์ดํฐ๋ฅผ ํํํ๊ธฐ์๋ ์ข์ง๋ง, ํ๋ก์ฐ๋ ์กฐ๊ฑด๋ถ ์ํฉ์ ํํํ๊ธฐ ์ด๋ ต๋ค๋ ๋จ์ ์ด ์๋ค.
Gradle
ํ์ฌ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋๋ ๋น๋ ๋๊ตฌ
Gradle์ ํ๋ก์ ํธ๋ฅผ ์ํ ๋ฒ์ฉ ๋น๋ ๋๊ตฌ์ด๋ค. ์๋๋ก์ด๋ ์คํ๋์ค์์ ๊ธฐ๋ณธ ๋น๋์์คํ ์ผ๋ก ์ฌ์ฉ
Ant์ ์ ์ฐ์ฑ(๊ธฐ๋ณธ์ ์ธ ๋น๋ ๋๊ตฌ ๊ธฐ๋ฅ)๊ณผ ํจ๊ณผ์ ์ธ ๋น๋ ํด์ธ Maven์ ํธ๋ฆฌ์ฑ(์์กด ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๊ด๋ฆฌ ๊ธฐ๋ฅ)์ ์กฐํฉํ์ฌ ๋ง์ ์คํ์์ค ํ๋ก์ ํธ์ ๋น๋ ์์คํ ์ผ๋ก ์ฑํ๋๊ณ ์๋ค
xml ์ธ์ด์ ๋ํ ๋จ์ ๋ Groovy ์ธ์ด(JVM ํ๊ฒฝ์ธ์ด)๋ฅผ ์ฌ์ฉํด ํด๊ฒฐ
Gradle์ Groovy DSL๋ก ์์ฑํ๋ฉฐ, ์ค์ ์ ๋ณด๋ ๋ณ์์ ๊ฐ์ ๋ฃ๋ ํํ๋ก, ๋์ ์ธ ๋น๋๋ Groovy ์คํฌ๋ฆฝํธ๋ก Gradle์ฉ ํ๋ฌ๊ทธ์ธ์ ํธ์ถํ๊ฑฐ๋ ์ง์ ์ฝ๋๋ฅผ ์งค ์ ์๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก ํ๋ก์ ํธ ํ์์ build.gradle
ํ์ผ๋ก ์์ฑ์ด ๋๋ฉฐ, ํ๋ก์ ํธ์์ ์ฌ์ฉํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ฒ์ ์ ๊ด๋ฆฌํ ์ ์๋ค.
plugins {
id 'org.springframework.boot' version '2.4.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'dh0023'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11' // java version
repositories {
mavenCentral() // mavenCentral์์ ๋ค์ด ๋ฐ์
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
sourceCompatibility
: Java Versiondependencies
: ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์์กด์ฑ ๊ด๋ฆฌ
๋ง์ฝ ์ธํ ๋ฆฌ์ ์ด๋ก ํ๋ก์ ํธ ์คํ์์ Build and run์ด Gradle๋ก ๋์ด์์ผ๋ฉด, ์คํ ์๋๊ฐ ๋๋ฆฐ ๊ฒฝ์ฐ๊ฐ ์์ผ๋ฏ๋ก ์๋์ ๊ฐ์ด ์ค์ ์ intellij๋ก ๋ณ๊ฒฝํด์ฃผ๋ ๊ฒ์ด ์ข๋ค.


๋ค์๊ณผ ๊ฐ์ด Gradle ์์ ์์กด์ฑ์ ํ์ธํ ์ ์๋ค.
CLI๋ก ๋น๋ํ๊ธฐ
$ gradlew build
Welcome to Gradle 6.8.3!
Here are the highlights of this release:
- Faster Kotlin DSL script compilation
- Vendor selection for Java toolchains
- Convenient execution of tasks in composite builds
- Consistent dependency resolution
For more details see https://docs.gradle.org/6.8.3/release-notes.html
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
> Task :test
2021-04-12 00:28:06.153 INFO 12948 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
BUILD SUCCESSFUL in 1m 37s
6 actionable tasks: 6 executed
๋ค์์ฒ๋ผ build๋ฅผ ์ํํ๋ฉด ํ๋ก์ ํธ ํ์์ build({project๋ช
}/build/
)๊ฐ ์์ฑ๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
$ cd ./build/libs
$ ls -trl
total 36712
-rw-r--r-- 1 dh0023 staff 18794659 4 12 00:27 spring-mvc-0.0.1-SNAPSHOT.jar
/builds/libs
ํ์์ jar
ํ์ผ์ด ์์ฑ๋ ๊ฒ์ ๋ณผ ์ ์์ผ๋ฉฐ,
$ java -jar ./spring-mvc-0.0.1-SNAPSHOT.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.4)
2021-04-12 00:29:14.647 INFO 14240 --- [ main] dh0023.springmvc.SpringMvcApplication : Starting SpringMvcApplication using Java 15.0.2 on dahyeui-MacBook-Pro.local with PID 14240 (/Users/dh0023/Develop/spring/spring-mvc/build/libs/spring-mvc-0.0.1-SNAPSHOT.jar started by dh0023 in /Users/dh0023/Develop/spring/spring-mvc/build/libs)
2021-04-12 00:29:14.653 INFO 14240 --- [ main] dh0023.springmvc.SpringMvcApplication : No active profile set, falling back to default profiles: default
2021-04-12 00:29:15.049 INFO 14240 --- [ main] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2021-04-12 00:29:20.242 INFO 14240 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-04-12 00:29:20.287 INFO 14240 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-04-12 00:29:20.288 INFO 14240 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.44]
2021-04-12 00:29:20.673 INFO 14240 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-04-12 00:29:20.674 INFO 14240 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 5622 ms
2021-04-12 00:29:21.827 INFO 14240 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-04-12 00:29:23.268 INFO 14240 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-04-12 00:29:23.294 INFO 14240 --- [ main] dh0023.springmvc.SpringMvcApplication : Started SpringMvcApplication in 12.135 seconds (JVM running for 14.029)
๋ก ์คํ๋ง ์๋น์ค๋ฅผ ์คํํ ์ ์๋ค.
๋ง์ฝ์ ์์ฑ๋ ๋น๋๋ฅผ ์ง์ฐ๊ณ ์ถ์ผ๋ฉด gradlew clean
์ ์ํํ๋ฉด๋๋ค.
$ gradlew clean
BUILD SUCCESSFUL in 2s
1 actionable task: 1 executed
~/Develop/spring/spring-mvc
$ ls -trl
total 56
drwxr-xr-x@ 4 dh0023 staff 128 4 11 13:21 src
-rw-r--r--@ 1 dh0023 staff 32 4 11 13:21 settings.gradle
-rw-r--r--@ 1 dh0023 staff 2763 4 11 13:21 gradlew.bat
-rwxr-xr-x@ 1 dh0023 staff 5766 4 11 13:21 gradlew
drwxr-xr-x@ 3 dh0023 staff 96 4 11 13:21 gradle
-rw-r--r--@ 1 dh0023 staff 1435 4 11 13:21 HELP.md
-rw-r--r-- 1 dh0023 staff 124 4 11 22:24 README.md
drwxr-xr-x 4 dh0023 staff 128 4 12 00:20 out
-rw-r--r--@ 1 dh0023 staff 634 4 12 00:21 build.gradle
Gradle vs Maven
Maven์ Build๋ผ๋ ๋์ ์ธ ์์๋ฅผ XML๋ก ์ ์ํ๊ธฐ์ ์ด๋ ค์ด ๋ถ๋ถ์ด ๋ง๋ค.
์ค์ ๋ด์ฉ์ด ๊ธธ์ด์ง๊ณ ๊ฐ๋ ์ฑ์ด ๋จ์ด์ง
์์กด ๊ด๊ณ๊ฐ ๋ณต์กํ ํ๋ก์ ํธ ์ค์ ํ๊ธฐ์ ๋ถ์ ์
์์ ๊ตฌ์กฐ๋ฅผ ์ด์ฉํ ๋ฉํฐ ๋ชจ๋ ๊ตฌํ
ํน์ ์ค์ ์ ์์์ ๋ชจ๋์์ ๊ณต์ ํ๊ธฐ ์ํด์๋ ๋ถ๋ชจ ํ๋ก์ ํธ๋ฅผ ์์ฑํ์ฌ ์์ํ๊ฒ ํด์ผํจ(์์์ ๋จ์ )
Gradle์ Groovy DSL์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์, ๋์ ์ธ ๋น๋๋ ๋น๋ ์คํฌ๋ฆฝํธ๋ก ํ๋ฌ๊ทธ์ธ์ ํธ์ถํ๊ฑฐ๋ ์ง์ ์ฝ๋๋ฅผ ์งค ์ ์๋ค.
Configuration Injection ๋ฐฉ์์ ์ฌ์ฉํด ๊ณตํต ๋ชจ๋์ ์์ํด์ ์ฌ์ฉํ๋ ๋จ์ ์ปค๋ฒ
์ค์ ์ฃผ์ ์ ํ๋ก์ ํธ์ ์กฐ๊ฑด์ ํ์ธํ ์ ์์ด์ ํ๋ก์ ํธ๋ณ๋ก ์ฃผ์ ๋๋ ์ค์ ์ ๋ค๋ฅด๊ฒ ํ ์ ์๋ค.
์ฐธ๊ณ
Last updated
Was this helpful?