아무거나

build.gradle 간략 설명 본문

Java/Gradle & Maven

build.gradle 간략 설명

전봉근 2019. 8. 19. 10:24
반응형

[build.gradle 간략 설명]

1. build.gradle 에 spring-boot plugin 사용을 위한 buildscript 설정을추가한다.

buildscript {
    ext {
    	springBootVersion = '1.5.9.RELEASE'
    }
    repositories {
    	mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath "io.spring.gradle:dependency-management-plugin:1.0.4.RELEASE"
    }
}

 

// buildscript 는 gradle 로 task 를 수행할 때에 사용되는 설정이다. 즉, 소스 컴파일과는 무관한다. 그러므로 dependency 를 추가할 때 

// buildscript 안에다가 정의하는 것과 밖에다가 정의하는 것은 매우 큰 차이가 있다.

 

2. springboot plugin을 적용

apply plugin: 'java'

apply plugin: 'eclipse'

apply plugin: 'org.springframework.boot'

 

3. 자바 소스 버젼, 컴파일 버젼, 인코딩을 설정한다.

group = 'com.ws'

version = '0.0.1'

sourceCompatibility = 1.8

targetCompatibility = 1.8

compileJava.options.encoding = 'UTF-8'

 

4. 라이브러리들을 가져올 레파지토리를 등록

repositories {

    mavenCentral()

}

 

5. 이제 스프링 부트의 라이브러리를 추가해보자.

dependencies {
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile 'pl.allegro.tech.boot:handlebars-spring-boot-starter:0.2.15'
    compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.5.0'
    compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.5.0'
    runtime('com.h2database:h2')
    compileOnly('org.projectlombok:lombok')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    compile 'commons-io:commons-io:2.4'
}

 

// 다시 간략히(적당히 대충) 말하지만 buildscript 안에서 정의된 dependencies 는 task 사용할 때 

// 사용되는 라이브러리이며,buildscript 밖에서 정의된 dependencies 는 소스를 컴파일할 때 등에 사용된다.

        // 라이브러리를 등록할 때에 버젼 지정을 안하는 것은 ‘spring-boot’ 플러그인을 적용시에 관련된 라이브러리에 버젼이 이미 설정되어있기 때문에 생략이 가능하다.​ 

반응형
Comments