【问题标题】:Override Spring Starter Version version in gradle在 gradle 中覆盖 Spring Starter Version 版本
【发布时间】:2017-12-18 18:11:30
【问题描述】:

我想要在 gradle 中等同于 properties 的 maven:

<properties>
        <spring-batch.version>4.0.0.M2</spring-batch.version>
</properties>

当我在build.gradle 中添加ext['spring-batch.version'] = '4.0.0.M2' 时,导入不起作用。

buildscript {
    ext {
        springBootVersion = '1.5.4.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

ext['spring-batch.version'] = '4.0.0.M2'

dependencies {
    compile('org.springframework.boot:spring-boot-starter-batch')
    compile("org.hsqldb:hsqldb")
}

我也尝试在gradle.properties 中添加spring-batch.version=4.0.0.M2,但也不起作用。

【问题讨论】:

    标签: java spring maven spring-boot gradle


    【解决方案1】:

    首先我会像这样使用新的插件机制:

    buildscript {
        repositories { mavenCentral() }
    }
    
    plugins {
        id 'java'
        id 'application' // for docker needed the main class in jar manifest
        id 'eclipse'
        id 'idea'
        id 'org.springframework.boot' version '1.5.4.RELEASE' // automagically includes io.spring.dependency-management
    }
    

    这应该会自动为您提供所有 org.springframework.boot 依赖项的正确版本,而无需明确指定它们(因此无需为 spring-batch 提供版本号。

    如果您想定义更多 project.ext 属性,请执行以下操作:

    ext {
        group = 'minimal_cloud_stream_producer'
        groupId = 'de.demo'
        baseName = 'minimal_cloud_stream_producer'
        port = 8080
    }
    

    也许你也必须添加一个dependencyManagement 部分,就像这样

    dependencyManagement {
        imports {
            mavenBom 'org.springframework.boot:spring-boot-starter-parent:1.5.4.RELEASE'
            mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR1'
        }
    }
    

    【讨论】:

    • 但 OP 希望指定与 1.5.4 BOM 中指定的版本不同的版本
    【解决方案2】:

    它失败了,因为4.0.0.M2 isn't in Maven central

    要修复它,请添加 Spring 里程碑 Maven 存储库:

    repositories {
        mavenCentral()
        maven { 
            url "http://repo.spring.io/libs-milestone" 
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-12
      • 1970-01-01
      • 2015-09-20
      • 2018-03-27
      • 1970-01-01
      • 2012-07-13
      • 1970-01-01
      • 2021-01-12
      • 1970-01-01
      相关资源
      最近更新 更多