2017-07-13 43 views
2

春入門版的版本,我想在gradle這個行家相當於properties覆蓋在gradle這個

<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,但也不能工作。

回答

4

它的失敗是因爲4.0.0.M2isn't in Maven central

爲了解決這個問題,加上春節里程碑Maven倉庫:

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

指定這是正確的答案! – chenrui

-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依賴關係的正確版本,而無需顯式指定它們(所以沒有必要給一個版本春天-批號

,如果你想進一步定義project.ext性質,這樣做的一樣:

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

也許你^ h AVE添加dependencyManagement部分太像這樣

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

但OP要指定一個不同的版本比什麼在1.5.4 BOM – nickb