我有以下问题:项目有自己的buildscript部分:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
当我将它作为子项目包含到另一个(也有类似的buildscript部分)时,我得到以下错误:
* What went wrong: A problem occurred evaluating project ':blablabla'.
> Cannot change dependencies of configuration ':blablabla:classpath' after it has been resolved.
这个buildcript对于他们两个都是强制性的,因为我需要让两个场景工作:
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
s 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 :(得分:0)
挖掘一段时间终于找到了合理的解决方案:您可以简单地切断子项目中的buildscript
部分,只需条件检查当前项目是否作为根目录调用:
if (project == rootProject) {
buildscript {
// ...
}
}
答案 1 :(得分:0)
要使父项目构建some-subproject
,需要进行两项更改。
在父项目的build.gradle
文件中
dependencies {
...
compile project(':some-subproject')
...
}
在父项目的setting.gradle
include ':some-subproject'