Spring Boot에서 Spring Framework 버전 지정하기

  • Post author:
  • Post category:칼럼
  • Post comments:0 Comments
  • Post last modified:August 16, 2015

Spring Boot로 프로젝트를 구성하면 현재 Spring Boot에 미리 설정된 기본 버전에 맞춰서 그 하위 스프링 프로젝트의 버전을 알아서 정한다. 대체로 해당 시점에 출시된 최신 스프링 프레임워크보다 한 단계 아래로 맞춰진다고 생각하면 된다. 그러니 최신 버전이나 SNAPSHOT 빌드 등을 쓰고 싶다면 내가 원하는 버전을 강제로 지정한다. Maven을 이용하면 아주 쉬워서 아래처럼 spring.version 프로퍼티를 정의하면 된다.

<properties>
         <spring.version>4.2.0.RELEASE</spring.version>
</properties>

하지만 Gradle을 사용할 때는 이렇게 쉽게 되지 않고 Spring IO Platform을 꼭 이용하는 편이 좋다. 이렇게 말하는 이유는 Maven을 쓸 때도 Spring IO Platform이 도움이 되는 것 같기 때문이다. 다만 Maven을 쓸 때는 Spring IO Platform이 없어도 특별히 문제된 적이 없다. 아무튼 Gradle에 Spring IO Platform을 도입하기는 그리 어렵지 않아서 문서대로 설정하면 끝이다.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE'
    }
}

apply plugin: 'io.spring.dependency-management'

dependencyManagement {
    imports {
        mavenBom 'io.spring.platform:platform-bom:1.1.3.RELEASE'
    }
}

이렇게 Spring IO Platform을 적용했으면 이제 내가 쓸 Spring Framework의 버전을 지정하면 된다. 크게 두 가지 방법이 있는데 편한 쪽을 고르면 된다.

  1. build.gradle 수정하기
    dependencies {
     ext {
          spring.version = '4.2.0.RELEASE'
       }
    }
    
  2. gradle.properties 수정하기
    spring.version=4.2.0.RELEASE
    

자, 다 했으면 제대로 적용이 됐는지 확인해보자!

gradle -q dependencies myproject:dependencies 

출력을 자세히 뜯어보면 Spring Framework의 버전이 바뀐 걸 확인할 수 있다.

+--- org.springframework.security.oauth:spring-security-oauth2:2.0.7.RELEASE
|    +--- org.springframework:spring-beans:4.0.9.RELEASE -> 4.2.0.RELEASE (*)
|    +--- org.springframework:spring-core:4.0.9.RELEASE -> 4.2.0.RELEASE (*)
|    +--- org.springframework:spring-context:4.0.9.RELEASE -> 4.2.0.RELEASE (*)
|    +--- org.springframework:spring-webmvc:4.0.9.RELEASE -> 4.2.0.RELEASE (*)

번외

Spring IO Platform 대신 Gradle의 고유 기능을 이용하는 방법도 있긴 하다. 지저분해서 내키지는 않지만 다른 라이브러리를 쓸 때는 유용할지도 모르겠다.

configurations.all {
    resolutionStrategy {
        eachDependency {
            if (it.requested.group == 'org.springframework') {
                it.useVersion '4.2.0.RC3'
            }
        }
    }
}

이 구문을 build.gradle 파일에 넣어주면 끝난다.

Author Details
Kubernetes, DevSecOps, AWS, 클라우드 보안, 클라우드 비용관리, SaaS 의 활용과 내재화 등 소프트웨어 개발 전반에 도움이 필요하다면 도움을 요청하세요. 지인이라면 가볍게 도와드리겠습니다. 전문적인 도움이 필요하다면 저의 현업에 방해가 되지 않는 선에서 협의가능합니다.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments