programing

다중 모듈 Spring Boot 프로젝트의 Gradle 종속성 플러그인

minimums 2023. 7. 2. 19:10
반응형

다중 모듈 Spring Boot 프로젝트의 Gradle 종속성 플러그인

Gradle 플러그인을 사용하는 다중 모듈 프로젝트에서 올바른 Gradle 구성은 어떻게 나타납니까?spring-boot-dependencies그리고.spring-boot?

다음과 같은 프로젝트 설정이 있습니다.

parent
  |
  + build.gradle
  |
  + alpha
  |   |
  |   + build.gradle
  |
  + beta
  |   |
  |   + build.gradle
  • parent모듈에 공통 프로젝트 구성이 포함되어 있습니다.
  • alphamodule은 spring-boot-dependencies bom에 지정된 버전 번호를 사용하여 종속성을 가져오는 모듈이지만 의 결과는 표준 jar입니다.
  • beta모듈은 다음에 의존하는 모듈입니다.alpha실행 가능한 Spring Boot jar 파일(모든 종속성 포함)이 생성됩니다.결과적으로, 이 프로젝트는 두 가지를 모두 필요로 합니다.spring-boot-dependencies뿐만 아니라spring-boot플러그인

Gradle 파일을 DRY 상태로 유지하기 위해 공통 모듈 스크립트를 부모님의 파일에 추출했습니다.build.gradle파일.

실행 시도 횟수$ gradle build아래의 프로젝트 구성을 사용하면 다음과 같은 결과를 얻을 수 있습니다.

> Plugin with id 'io.spring.dependency-management' not found.

부모의 기쁨빌드

allprojects {
    group = "com.example"
    version '0.0.1-SNAPSHOT'

    ext {
        dependencyManagementPluginVersion = '0.5.3.RELEASE'
        springBootVersion = '1.3.0.RC1'
    }

    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
}

subprojects {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    buildscript {
        repositories {
            jcenter()
            maven { url "https://repo.spring.io/snapshot" }
            maven { url "https://repo.spring.io/milestone" }
        }
        dependencies {
            classpath("io.spring.gradle:dependency-management-plugin:${dependencyManagementPluginVersion}")
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }

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

    dependencyManagement {
        imports {
            mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
//            mavenBom("org.springframework.boot:spring-boot-starter-parent:${springBootVersion}")
        }
    }
}

알파 빌드.그레이들

dependencies {
    compile('org.springframework:spring-web')
}

베타 그라들빌드

apply plugin: 'spring-boot'

dependencies {
    compile project(':alpha')
    compile('org.springframework.boot:spring-boot-starter')
    compile('org.springframework.boot:spring-boot-starter-web')
}

댓글:

  • 의 동작spring-boot플러그인은 Spring Boot 1.3.0에서 변경되었습니다.M1
  • Gradle 버전: 2.8
  • Spring Boot 버전 1.3.0.RC1

알고 보니parent/build.gradle다음과 같은 방식으로 재배열해야 합니다.

buildscript {
    ext {
        dependencyManagementPluginVersion = '0.5.3.RELEASE'
        springBootVersion = '1.3.0.RC1'
    }
    repositories {
        jcenter()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath("io.spring.gradle:dependency-management-plugin:${dependencyManagementPluginVersion}")
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

allprojects {
    group = "com.example"
    version '0.0.1-SNAPSHOT'

    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
}

subprojects {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

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

    dependencyManagement {
        imports {
            mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
//          mavenBom("org.springframework.boot:spring-boot-starter-parent:${springBootVersion}")
        }
    }
}

문제는 그 사실에 있습니다.buildscript하위 프로젝트의 블록은 실제로 잘 구성되었지만...엉뚱한 곳에이것.subprojects블록은 하위 프로젝트와 관련이 있지만 선언된 스크립트에서 평가되며 적용하려는 플러그인에 대해 선언된 종속성이 없습니다.

언급URL : https://stackoverflow.com/questions/33706957/gradle-dependency-plugin-in-a-multi-module-spring-boot-project

반응형