简体   繁体   中英

Override Spring Starter Version version in gradle

I would like the maven equivalent of properties in gradle:

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

When I added ext['spring-batch.version'] = '4.0.0.M2' in build.gradle , imports are not working.

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")
}

I also tried to add spring-batch.version=4.0.0.M2 in gradle.properties , but not working also.

It's failing because 4.0.0.M2 isn't in Maven central .

To fix it, add the Spring milestone Maven repository:

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

first I'd use the new plugin mechanis like so:

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
}

this should automagically give you the correct version of all org.springframework.boot dependencies, without having to specify them explicitly (so no need to give a version number for spring-batch.

if you'd like to define further project.ext properties, do so like:

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

maybe you have to add a dependencyManagement section too, like so

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM