younsik
younsik.tech
younsik
전체 방문자
오늘
어제

공지사항

  • 시리즈 모음
  • 분류 전체보기 (34)
    • Dev (17)
      • 일반 (2)
      • 환경세팅 (11)
      • Issue (4)
    • SpringBoot (4)
      • Boot (2)
      • JPA (2)
      • Redis (0)
      • Webflux (0)
    • ElasticStack (0)
      • Elasticsearch (0)
      • Logstash (0)
      • Kibana (0)
    • Docker&Kubernetes (0)
      • Docker (0)
      • Kubernetes (0)
    • Cloud (4)
      • AWS (4)
      • GCP (0)
    • Ops (2)
      • DevOps (1)
      • MLOps (1)
    • Database (1)
      • MySQL (1)
      • MongoDB (0)
      • Cassandra (0)
    • ML&DL (0)
      • Machine Learning (0)
      • Deep Learning (0)
    • Tensorflow (1)
      • Installation (1)
      • Basic (0)
      • TFX (0)
    • Pytorch (0)
      • Installation (0)
      • Basic (0)
    • Hands-on (5)
      • SpringBoot (5)

블로그 메뉴

  • 홈
  • Github
  • GitBlog
  • 태그
  • 방명록

링크 모음

실무 예제로 배우는 Elasticsearch 검색엔진

인기 글

태그

  • Intel
  • erlang
  • Issue
  • Spring
  • gradle
  • boot
  • JPA
  • zplug
  • ubuntu
  • codesource
  • Java
  • openjdk
  • jenv
  • 개발환경
  • Node
  • miniforge
  • AWS
  • docker
  • MVC
  • mlops
  • Intellij
  • amvu
  • GIT
  • Homebrew
  • MAC
  • 환경세팅
  • asdf
  • Beginner
  • Kubeflow
  • m1

최근 댓글

최근 글

hELLO · Designed By 정상우.
younsik

younsik.tech

SpringBoot/Boot

[Gradle] 외부 파일로 Dependency 버전 관리 하기

2022. 4. 14. 16:25

일반적으로 spring boot를 사용하는 경우 io.spring.dependency-management 플러그인으로 dependency 관리를 한다

 

일부 몇몇 외부 라이브러리 사용하는 경우 다음과 같이 build.gradle 내에서 buildscript에 선언하여 version을 명시할 수 있다

// build.gralde

buildscript {
    ext {
        resilience4jVersion = '1.7.1'
    }
}

 

 

그러나 가끔 멀티 모듈을 사용할 경우 중복되는 라이브러리들의 버전은 별도로 관리하고 싶은 경우가 있다

 

방법 1. 별도 gradle 파일 이용

// versions.gradle 파일을 생성하고 다음과 같이 작성한다

ext.versions = [:]

versions.spring_boot = '2.6.6'
versoins.spring_cloud_deps = '2021.01'
versions.resilience4j = '1.7.1'

ext.versions = versions
// build.gradle에서 versions.gradle 사용

buildscript {
    apply from: "${rootProject.getRootDir()}/versoins.gradle"
    
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$versions.spring_boot"
    }
}

subprojects {

    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'java-library'

    sourceCompatibility = '11'
    
    dependencies {
        implementation "io.github.resilience4j:resilience4j-spring-boot2:$versions.resilience4j"
    }
}

방법 2. toml 사용

// libs.version.toml 작성

[versions]
springBoot = "2.6.6"
bootDependency = "1.0.11.RELEASE"
springCloud = "2021.0.1"

[libraries]
# bundles boot-starter
boot-starter = {module = "org.springframework.boot:spring-boot-starter"}

# bundles boot-tester
boot-test = {module = "org.springframework.boot:spring-boot-starter-test"}

# bundles jackson
jackson-databind = {module = "com.fasterxml.jackson.core:jackson-databind"}
jackson-jsr310 = {module = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"}

# bundles common
commons-codec = { module = "commons-codec:commons-codec", version = "1.15" }
commons-lang3 = { group = "org.apache.commons", name = "commons-lang3", version = "3.12.0" }

# libs
fusionauth-jwt = { group = "io.fusionauth", name = "fusionauth-jwt", version = "4.3.1" }

[bundles]
boot-starter = ["boot-starter"]
jackson = ["jackson-databind", "jackson-jsr310"]
common = ["commons-lang3", "commons-codec"]
boot-test = ["boot-test"]

[plugins]
spring-boot = { id = "org.springframework.boot", version.ref = "springBoot" }
boot-dependency = { id = "io.spring.dependency-management", version.ref = "bootDependency" }
// settings.gradle 다음 내용 추가

dependencyResolutionManagement {
    versionCatalogs {
        libs {
            from(files("${rootDir}/libs.versions.toml"))
        }
    }
}
// build.gradle 작성 (rootDir)

plugins {
    id 'java-library'
    alias(libs.plugins.spring.boot) apply false
    alias(libs.plugins.boot.dependency)
}

subprojects {

    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'java-library'

    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11

    repositories {
        mavenCentral()
    }

    dependencies {
        
        implementation libs.bundles.boot.starter

        // jackson
        implementation libs.bundles.jackson

        compileOnly 'org.projectlombok:lombok'
        annotationProcessor 'org.projectlombok:lombok'

        // test
        testImplementation libs.bundles.boot.test
    }
}
// build.gradle 작성 (module)

dependencies {

    //common
    implementation libs.bundles.common

    // libs
    implementation libs.fusionauth.jwt
}
저작자표시 비영리 변경금지 (새창열림)

'SpringBoot > Boot' 카테고리의 다른 글

[Bean] Router 구현  (0) 2022.04.12
    'SpringBoot/Boot' 카테고리의 다른 글
    • [Bean] Router 구현
    younsik
    younsik
    younsik.tech의 기술 블로그

    티스토리툴바