我在gradle中有多项目构建。在build.gradle
中,我对两个或更多项目的依赖性相同:
project(":pr-common") {
dependencies {
compile "joda-time:joda-time:2.3"
compile "org.joda:joda-convert:1.6"
}
}
project(":pr-domain") {
dependencies {
compile "joda-time:joda-time:2.3"
compile "org.joda:joda-convert:1.6"
}
}
我可以以某种方式分组和重用这些依赖项吗?我想要这样的东西:
def joda = [
compile "joda-time:joda-time:2.3",
compile "org.joda:joda-convert:1.6"
]
project(":pr-common") {
dependencies {
joda
}
}
project(":pr-domain") {
dependencies {
joda
}
}
答案 0 :(得分:1)
您不能以您建议的方式重用依赖项。相反,您可以使用以下代码。
build.gradle (根项目)
subprojects.findAll { it.path.contains('pr') }.each { //whatever search condition
it.plugins.apply 'groovy'
it.dependencies {
compile 'com.google.inject:guice:3.0'
compile 'com.google.guava:guava:15.0'
}
}