如何删除依赖项和存储库的重复定义?
问题描述:
我有了存储库和相关的复制关系的构建脚本:如何删除依赖项和存储库的重复定义?
apply plugin: 'groovy'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.codehaus.groovy:groovy-all:2.0.5'
classpath 'org.apache.knox:gateway-shell:0.6.0'
classpath 'commons-io:commons-io:2.4'
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.0.5'
compile 'org.apache.knox:gateway-shell:0.6.0'
compile 'commons-io:commons-io:2.4'
}
如果我注释掉无论是部分的,我收到生成错误。有没有办法使用存储库和依赖关系的单一定义?
注:构建脚本的其余部分...
task wrapper(type: Wrapper) {
gradleVersion = '2.9'
}
sourceSets {
main {
groovy {
srcDirs = ['scripts']
}
}
}
/* Task to run script */
tasks.addRule("Pattern: filename.groovy") { String taskName ->
if (taskName.endsWith('.groovy')) {
FileTree tree = fileTree('./scripts/').include('**/*.groovy')
tree.each {File file ->
if (file.absolutePath.endsWith(taskName)) {
task(taskName, dependsOn:'classes', type: JavaExec) {
Properties props = new Properties()
props.load(new FileInputStream("$projectDir/connection.properties"))
environment 'gateway', props.gateway
environment 'username', props.username
environment 'password', props.password
// the classname is the scriptname minus the extension
main = org.apache.commons.io.FilenameUtils.getBaseName(taskName)
classpath = sourceSets.main.runtimeClasspath
}
}
}
}
}
答
,如果你有一个多模块项目,你可以添加到根gradle这个buildscript
allprojects {
repositories {
jcenter() or mavenCentral()
}
}
+0
OP的问题是关于同一个build.gradle文件的两个存储库和两个依赖项部分,而不是关于多个模块。 – RaGe
现在有办法消除这种重复。 – Opal
不,它们的两个部分是针对不同的东西的,buildscript部分是build.gradle文件的其余部分,而外部部分是针对源代码的。看到这里:http://*.com/questions/13923766/gradle-buildscript-dependencies – RaGe