无法在gradle.properties中保留依赖版本

问题描述 投票:0回答:1

我需要将依赖关系的版本保留在gradle.properties中。

gradle.properties:

springBootVersion = '2.1.9.RELEASE'

build.gradle:

plugins {
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'org.springframework.boot' version '2.1.9.RELEASE'
}

subprojects {
    repositories {
        mavenCentral()
    }

    configurations.all {
        resolutionStrategy {
            failOnVersionConflict()
        }
    }

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

    dependencyManagement {
        dependencies {
            dependency "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
            dependency "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
        }
    }

    sourceCompatibility = 11
    targetCompatibility = 11

    tasks.withType(JavaCompile){
        options.encoding = 'UTF-8'
    }
}

settings.gradle:

include 'api'

api / build.gradle:

apply plugin: 'org.springframework.boot'

archivesBaseName = 'phone-gift-processing-api'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

./gradlew clean build的输出:

> Task :api:compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':api:compileJava'.
> Could not resolve all files for configuration ':api:compileClasspath'.
   > Could not find org.springframework.boot:spring-boot-starter-web:'2.1.9.RELEASE'.
     Required by:
         project :api

即Gradle使用springBootVersion,但由于某种原因未能绑定依赖项。

[当我用${springBootVersion}替换${springBootVersion}时,构建成功。

java gradle dependency-management
1个回答
0
投票

gradle.properties中格式错误。代替这个:

springBootVersion = '2.1.9.RELEASE'

尝试一下:

springBootVersion=2.1.9.RELEASE

(空格是可选的,但重要的部分是您不应在值周围使用引号。)

© www.soinside.com 2019 - 2024. All rights reserved.