스프링 부트 2.0 을 사용하면서 패키징과 관련된 찝찝한 느낌을 받고 있는 요즘이다.
그 주요 원인은 스프링 부트 그레이들 플러그인 2.0 때문이다. 스프링 부트 그레이들 플러그인 2.0이 되면서 기존에 있던 bootRepackage
가 bootJar
와 bootWar
으로 변경(Spring Boot’s new Gradle plugin)되면서 부터다.
실행가능한 jar와 war를 만드는데 사용했던 bootRepackage
를 배포파일에 따라서 각각 Jar
는 bootJar
와 War
는 bootWar
로 확장하는 과정에서 이런 상황이 발생했다.
핵심요점만 이야기하자면 bootJar
와 bootWar
를 비활성화하면 패키징 태스크가 실행되지 않는다.
//bootJar 비활성화시
bootJar.enabled = false
jar.enabled = true
//bootWar 비활성화시
bootWar.enabled = false
war.enabled = true
위와 같은 형태로 상위 태스크를 활성화시켜줘야지만 패키징 태스크가 실행된다. 이러한 사실을 알게된 것은
가 있었고, 오늘은 EBS(AWS Elastic Beanstalk)에서 "구성 파일(.ebextensions)을 사용하여 고급 환경 사용자 지정" 기능을 사용하기 위해서 프로젝트 내에 .ebextensions
디렉터리를 war 파일 패키징시 이동하기 위해 그레이들내에서 다음과 같이 선언했는데 .ebextensions
디렉터리가 패키징에서 누락된 것을 발견했다.
build.gradle
project(":api-module") {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
war {
from('./src/main/ebextensions') {
into('.ebextensions')
}
}
dependencies {
compile project(":core-module")
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-hateoas')
compile('org.springframework.boot:spring-boot-starter-web-services')
compile('org.springframework.boot:spring-boot-starter-webflux')
compile('org.springframework.data:spring-data-rest-hal-browser')
compileOnly "org.springframework.boot:spring-boot-configuration-processor"
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('io.projectreactor:reactor-test')
}
}
위와 같이 모듈을 정의했는데, war
태스크를 정의한 부분이 무시됐다. (이런!!)
하지만 그렇다고 분노하거나 노여워하지 말자(그건 내가 다 했으니…).
여기서 대응할 수 있는 방법은 크게 2가지가 있다.
-
새로추가된
booWar
태스크를 사용하는 경우 -
기존
war
태스크를 유지하는 경우
Note
|
스프링 부트를 기반으로 할 때는 실행가능하게 패키징(Repackaging)을 하는 |
project(":api-module") {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
bootWar {
from('./src/main/ebextensions') {
into('.ebextensions')
}
}
dependencies {
compile project(":core-module")
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-hateoas')
compile('org.springframework.boot:spring-boot-starter-web-services')
compile('org.springframework.boot:spring-boot-starter-webflux')
compile('org.springframework.data:spring-data-rest-hal-browser')
compileOnly "org.springframework.boot:spring-boot-configuration-processor"
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('io.projectreactor:reactor-test')
}
}
Note
|
톰캣과 같은 WAS에 war 파일을 배포한다면 실행가능하게 패키징을 필요로 하지 않으니 |
project(":api-module") {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
bootWar.enabled = false // (1)
war.enabled = true // (2)
war {
from('./src/main/ebextensions') {
into('.ebextensions')
}
}
dependencies {
compile project(":core-module")
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-hateoas')
compile('org.springframework.boot:spring-boot-starter-web-services')
compile('org.springframework.boot:spring-boot-starter-webflux')
compile('org.springframework.data:spring-data-rest-hal-browser')
compileOnly "org.springframework.boot:spring-boot-configuration-processor"
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('io.projectreactor:reactor-test')
}
}
-
bootWar
를 비활성화한다. -
war
를 활성화한다.
-
기술을 사용할 때는 참고문서를 보자.
-
4.3. Packaging executable and normal archives - Spring Boot Gradle Plugin
-
… 문서에 있긴 있구나. 거론을 했는데 내가 자세히 안봤구나… 그랬구나…
-
'Java > SpringBoot' 카테고리의 다른 글
[springboot] T Acacemy 교육자료 1/3:: 스프링 부트 소개 Boot Spring Boot (0) | 2018.09.27 |
---|---|
[springboot] Boot Spring Boot! 북콘서트 (0) | 2018.08.17 |
Boot Spring Boot: 스프링 부트 참고서 (0) | 2018.07.09 |
[springboot] 그레이들 플러그인 bootJar.enabled=false 처리 후 jar 파일 생성이 안된다면! (0) | 2018.07.02 |
Spring Boot 1.5.15, 2.0.3 출시, 롬복(lombok) 1.16.22 관련 내용 (0) | 2018.06.15 |