[Spring] gradle 정리

2022. 9. 7. 10:37Dev/Spring

Language

* Groovy ( default )

* Kotlin

 

File
  • gradlew

리눅스 or OSX 용 실행 쉘 스크립트 파일 =>

./gradlew :서브프로젝트:build
  • gradlew.bat

윈도우용 실행 스크립트 파일

  • settings.gradle

프로젝트의 구성 정보 파일 > 모노레포에서 멀티프로젝트 구성 시, 하위 프로젝트 구성을 설정

rootProject.name = 'root-project'
include 'sub-project-1'
include 'sub-project-2'
include 'sub-project-3'
...
  • build.gradle

프로젝트의 라이브러리 의존성, 플러그인 등을 설정하는 빌드 스크립트 파일로 Node에서 package.json / golang에서 go.mod의 기능을 수행함

  • gradle > wrapper > gradle-wrapper.jar

실행 스크립트 파일을 jar로 압축한 파일

  • gradle > wrapper > gradle-wrapper.properties

gradlew wrapper의 설정 파일

 

Syntax

- plugin : 플러그인 추가

apply plugin: 'java'
apply plugin: 'org.springframework.boot'

//혹은
plugins {
	id 'java'
    id 'org.springframework.boot'
}

 

- repositories : 오픈 소스 라이브러리를 호스팅하는 저장소 ( mavenCentral(), jCenter(), google() 등 )

// 프로젝트의 모든 종속성에 대한 레포지토리
repositories {
    mavenCentral()
    maven {
        url 'https://repo.spring.io/libs-milestone'
    }
}

// 빌드스크립트의 디펜던시의 종속성에 대한 레포지토리
buildscript {
    repositories {
        jcenter()
    }
}

 

 - ext : 변수 선언

ext {
    springBootVersion = '1.5.22.RELEASE'
    springVersion = '4.3.25.RELEASE'
}

//아래와 같이 변수를 가져올 수 있다
...
dependencies {
    classpath 'org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion'
    classpath 'org.springframework:springloaded:1.2.0.RELEASE'
}

 

- compile vs implementation

A <- B <- C 처럼, B와 C가 모두 A 모듈을 의존하고 있을 때

compile: A 수정 시 B와 C 모두 다시 빌드됨

implementation: A를 직접 의존하는 B만 다시 빌드됨

또한

compile: 연결된 API 모두 프로젝트에 의해 노출됨

implementation: 노출되지 않음

즉, 퍼포먼스적으로 implementation이 훨씬 유리하고, compile은 deperecated됨(gradle 3.0 이후부터)

 

'Dev > Spring' 카테고리의 다른 글

[Java] Stream api 정리  (0) 2022.09.17
[Java] @Entity 객체의 값 수정 시 자동 DB 갱신?  (0) 2022.03.03
What / Why Spring Bean ?  (0) 2021.06.28
Spring Annotation - Getter, Setter  (0) 2021.06.23