【问题标题】:Cannot keep dependency version in gradle.properties无法在 gradle.properties 中保留依赖项版本
【发布时间】:2019-10-17 15:43:59
【问题描述】:

我需要在 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】:

    gradle.properties 的格式有误。而不是这个:

    springBootVersion = '2.1.9.RELEASE'

    试试这个:

    springBootVersion=2.1.9.RELEASE

    (空格是可选的,但重要的是你不应该在值周围加上引号。)

    【讨论】:

    • 没错,我忘了 .properties 不是 gradle 文件。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    • 2023-03-12
    • 2022-01-02
    • 2022-01-11
    • 2019-12-25
    • 1970-01-01
    相关资源
    最近更新 更多