我有一个根build.gradle,其中包含一些变量,我希望将其作为某些子项目的全局变量,但不是所有子项目的全局变量
我创建了一个列表:
List spring_dependencies = [
"org.springframework:spring-beans:$springVersion",
"org.springframework:spring-core:$springVersion",
"org.springframework:spring-web:$springVersion",
]
我有一些不使用它进行编译的子项目,所以我只想添加:
compile spring_dependencies
到那些真正需要spring的项目。
如何在gradle中实现这种全局变量共享?
发布于 2012-10-17 13:18:55
我刚刚尝试过的一种方法(似乎很有效)是声明另一个子项目(我将其称为'spring'),它具有以下build.gradle
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile "org.springframework:spring-beans:$springVersion"
compile "org.springframework:spring-core:$springVersion"
compile "org.springframework:spring-web:$springVersion"
}
将此项目添加到子项目的settings.gradle
列表中,然后在需要spring库的build.gradle
中,您可以执行以下操作:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile project(':spring')
}
从您的spring
子项目中提取依赖项。
也许有更好的方法来达到同样的结果。:-/
https://stackoverflow.com/questions/12934601
复制相似问题