3

我有一个 Gradle 设置,我目前需要对 spring-boot 版本进行硬编码。是否可以使用依赖管理来做到这一点?该问题发生在包含实际代码的项目模块中。我需要打电话给:

springBoot {
    requiresUnpack = ["com.example:util"]
}

为此,我需要应用spring-boot plugin. 为了使该插件可用,我需要对"org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}". 为此,我需要指定springBootVersion硬编码...

这是我的父 gradle 文件:

buildscript {

    ext {
        springBootVersion = '1.4.0.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        classpath 'io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE'
    }
}

plugins {
    id "io.spring.dependency-management" version "0.6.0.RELEASE"
}

group 'test'


repositories {
    mavenCentral()
}

allprojects {
    apply plugin: 'java'
    apply plugin: 'io.spring.dependency-management'

    dependencyManagement {
        imports {
            // Note that these two BOM's are not always easy to combine, always define cloud first and try to find versions with same version of spring-boot when upgrading.
            mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.SR5'
            mavenBom 'io.spring.platform:platform-bom:2.0.7.RELEASE'

        }
    }
}

这是我的模块 gradle 文件:

group = "test"

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

sourceCompatibility = 1.8
targetCompatibility = 1.8

// Temporary fix for jersey
springBoot {
    requiresUnpack = ["com.example:util"]
}

如果我删除了对spring-boot-gradle-plugin父 gradle 文件中的依赖项,那么我不能apply plugin: 'spring-boot'在模块 gradle 文件中使用,并且没有定义 gradle DLS 方法springBoot {......

springBootVersion = '1.4.0.RELEASE'我可以在不必在我的父 gradle 文件中硬编码的情况下实现这一点吗?

4

0 回答 0