2016-01-09 113 views
0

我有以下問題:有項目有自己的buildscript部分:搖籃:包括與buildscript作爲子項目項目

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" 
    } 
} 

當我把它作爲一個子項目到另外一個(也具有類似buildscript節)我得到以下錯誤:因爲我需要得到2種情景工作

* What went wrong: A problem occurred evaluating project ':blablabla'. 
> Cannot change dependencies of configuration ':blablabla:classpath' after it has been resolved. 

這buildscript是必須對他們倆的:

  1. 當他們兩個都可以獨立建造時
  2. blablabla被視爲第一個子項目。

所以,問題是我如何重寫(或禁用)包含項目的buildscript部分?

編輯

我有如下配置:

// mainProject's build.gradle 

buildscript { 
    repositories { 
     mavenCentral() 
    } 

    dependencies { 
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" 
    } 
} 

plugins { 
    id 'org.jetbrains.intellij' version "0.0.36" 
} 

// Some other irrelevant stuff 

blablabla小號build.gradle

// subProject's build.gradle 

buildscript { 
    repositories { 
     mavenCentral() 
    } 

    dependencies { 
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" 
    } 
} 

plugins { 
    id 'org.jetbrains.intellij' version "0.0.36" 
} 

// Some other irrelevant stuff 

而且settings.gradle

// settings.gradle 

include ":subProject" 
+0

怎麼樣你包括project2作爲project1的子項目? – RaGe

+0

正確:在'settings.gradle'裏面我做:'include:blablabla' – alexeykudinkin

+0

請問你能否提供一個重現問題的例子? – Opal

回答

0

周圍挖了一段時間終於找到合理的解決辦法:你可以簡單地切斷buildscript部分在子項目只有條件檢查當前的項目是否被調用爲根之一:

if (project == rootProject) { 
    buildscript { 
    // ... 
    } 
}