gradle 多工程apply plugin問題
最近用gradle編譯spring cloud的項目,在父工程加入
subprojects {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
....
的時候,遇到了一個比較奇怪的問題
gradle subprojects plugin with id not found
后來找到一個臨時的方案拣宰,現(xiàn)在記錄在這里
假如我有兩個項目,一個是eureka-service吻谋, 一個是eureka-client,前者代表用eureka構(gòu)建的eureka的服務(wù)器现横,后者代表使用eureka構(gòu)建的客戶端漓拾,兩者其實有很多共同的build.gralde 元素阁最,最直白的就是對于spring boot等的plugin的引用
原始的erueka-client的build.gradle 文件
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'eureka-client'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencyManagement {
imports {
// mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR5'
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR4'
}
}
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-eureka')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.cloud:spring-cloud-starter-eureka-server')
}
原始的eureka-service的gradle文件
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'eureka-service'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencyManagement {
imports {
//mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR5'
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR4'
}
}
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-eureka-server')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
可以看到,除了dependencies這部分骇两,我們可以單獨存放速种,其他的,都是一樣的低千,我們完全可以放到父工程的gradle文件里配阵,于是就要這么辦,在父工程的build.gradle中
subprojects {
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencyManagement {
imports {
// mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR5'
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR4'
}
}
}
這時候栋操,問題就來了闸餐,會報錯饱亮,提示說找不到plugin java和org.springframework.boot等矾芙,查了網(wǎng)頁才知道要這么搞
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencyManagement {
imports {
// mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR5'
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR4'
}
}
}
感覺是在subprojects 里不能放置buildscript的東西,估計還是gradle生命周期的問題近上。