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 Version

  • dependencies : ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์˜์กด์„ฑ ๊ด€๋ฆฌ

๋งŒ์•ฝ ์ธํ…”๋ฆฌ์ œ์ด๋กœ ํ”„๋กœ์ ํŠธ ์‹คํ–‰์‹œ์— Build and run์ด Gradle๋กœ ๋˜์–ด์žˆ์œผ๋ฉด, ์‹คํ–‰ ์†๋„๊ฐ€ ๋Š๋ฆฐ ๊ฒฝ์šฐ๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค์ •์„ intellij๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

![](./assets/แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-04-11 แ„‹แ…ฉแ„’แ…ฎ 10.36.27.png)

๋‹ค์Œ๊ณผ ๊ฐ™์ด 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