๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
WEB/SPRING

[SPRING] ์ธํ…”๋ฆฌ์ œ์ด๋กœ ์Šคํ”„๋ง ๋ถ€ํŠธ ์‹œ์ž‘ํ•˜๊ธฐ

by ๋ญ‰๋ง๋ญ‰ 2021. 10. 4.

๐ŸŒธ์ธํ…”๋ฆฌ์ œ์ด์—์„œ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ํ›„ ๊นƒ๊ณผ ๊นƒํ—ˆ๋ธŒ ์‚ฌ์šฉํ•˜๊ธฐ

Gradle๋กœ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ํ›„ ๊ธฐ๋ณธ์ ์œผ๋กœ ์„ค์น˜๋˜๋Š” .gradle, .idea๋ฅผ .gitignore์— ๋“ฑ๋ก!

  • gitignore ์‚ฌ์šฉ ์œ„ํ•ด์„  ctrl + shift + a๋กœ action ๊ฒ€์ƒ‰์ฐฝ ์—ด๊ณ  plugins ๊ฒ€์ƒ‰ - Marketplace์—์„œ .gitignore ์„œ์น˜ ํ›„ ์„ค์น˜

๐ŸŒธ๊ทธ๋ ˆ์ด๋“ค ํ”„๋กœ์ ํŠธ๋ฅผ ์Šคํ”„๋ง ๋ถ€ํŠธ ํ”„๋กœ์ ํŠธ๋กœ ๋ณ€๊ฒฝํ•˜๊ธฐ

> build.gradle ํŒŒ์ผ ์ˆ˜์ •

buildscript {  //'์ด ํ”„๋กœ์ ํŠธ์˜'('์ธํ…”๋ฆฌ์ œ์ด์˜' ์•„๋‹˜!) ํ”Œ๋Ÿฌ๊ทธ์ธ ์˜์กด์„ฑ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ ์„ค์ •.
    ext {  //build.gradle์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์ „์—ญ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•˜๊ฒ ๋‹ค
        springBootVersion = '2.1.9.RELEASE'   //springBootVersion์ด๋ผ๋Š” ์ „์—ญ๋ณ€์ˆ˜ ์ƒ์„ฑ. ๊ทธ ๊ฐ’์€ 2.1.9.RELEASE
    } //spring-boot-gradle-plugin์ด๋ผ๋Š” ์Šคํ”„๋ง๋ถ€ํŠธ ๊ทธ๋ ˆ์ด๋“ค ํ”Œ๋Ÿฌ๊ทธ์ธ์˜ 2.1.9.RELEASE๋ฅผ ์˜์กด์„ฑ์œผ๋กœ ๋ฐ›๊ฒ ๋‹ค
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

//์•ž์„œ ์„ ์–ธํ•œ ํ”Œ๋Ÿฌ๊ทธ์ธ ์˜์กด์„ฑ๋“ค์„ ์ ์šฉํ•  ๊ฒƒ์ธ์ง€๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ์ฝ”๋“œ๋“ค. ์ž๋ฐ”์™€ ์Šคํ”„๋ง ๋ถ€ํŠธ ์‚ฌ์šฉ ์œ„ํ•ด์„œ๋Š” ํ•„์ˆ˜ ํ”Œ๋Ÿฌ๊ทธ์ธ.
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'  //์Šคํ”„๋ง๋ถ€ํŠธ์˜ ์˜์กด์„ฑ๋“ค์„ ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ

group 'com.jojoldu.book'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8

repositories { //๊ฐ์ข… ์˜์กด์„ฑ(๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ)๋“ค์„ ์–ด๋–ค ์›๊ฒฉ ์ €์žฅ์†Œ์—์„œ ๋ฐ›์„์ง€ ๊ฒฐ์ •
    mavenCentral()  //๊ธฐ๋ณธ์ ์œผ๋กœ ๋งŽ์ด ์‚ฌ์šฉ.
    jcenter()  //์ตœ๊ทผ์—๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์—…๋กœ๋“œ ๋‚œ์ด๋„๊ฐ€ ๋” ๊ฐ„๋‹จํ•œ ์–˜๋„ ๋งŽ์ด ์‚ฌ์šฉ.
}

//ํ”„๋กœ์ ํŠธ ๊ฐœ๋ฐœ์— ํ•„์š”ํ•œ ์˜์กด์„ฑ ์„ ์–ธ. ์˜์กด์„ฑ ์ฝ”๋“œ๋Š” ์ง์ ‘ ์ž‘์„ฑํ•ด๋„, ์ž๋™์™„์„ฑ์œผ๋กœ ๋งŒ๋“ค์–ด๋„ ๋˜๋Š”๋ฐ ํŠน์ • ๋ฒ„์ „ ๋ช…์‹œํ•˜๋ฉด ์•ˆ ๋จ. ๊ทธ๋ž˜์•ผ ์œ„์— ${springBootVersion} ๋”ฐ๋ผ๊ฐ
dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.projectlombok:lombok')  //ํ›„์— ๋‚˜์˜ฌ lombok ์œ„ํ•ด ๋ฏธ๋ฆฌ ์ถ”๊ฐ€ํ•จ
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

์˜ค๋ฅธ์ชฝ ์ƒ๋‹จ์— ๋œจ๋Š” ์ฝ”๋ผ๋ฆฌ ๋ˆŒ๋Ÿฌ์„œ ๋ฐ˜์˜ํ•ด์ฃผ๊ธฐ!

 

ํ”„๋กœ์ ํŠธ ์˜์กด์„ฑ์ด ์ž˜ ๋ฐ›์•„์กŒ๋Š”์ง€ ํ™•์ธ (์šฐ์ธก ์ƒ๋‹จ gradle ํด๋ฆญ)

๋Œ“๊ธ€