2

I have a build script that has duplication of the repositories and dependencies:

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'
}

If I comment out either of the sections, I receive build errors. Is there a way to use a single definition of repositories and dependencies?


NOTE: The rest of the build script...

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
                }
            }
        }
    }
}
Chris Snow
  • 23,813
  • 35
  • 144
  • 309
  • There's now way to eliminate this duplication. – Opal Dec 21 '15 at 17:32
  • No, they two sections are meant for different things, the buildscript section is for the rest of build.gradle file while the outside section is for your source code. see here: http://stackoverflow.com/questions/13923766/gradle-buildscript-dependencies – RaGe Dec 21 '15 at 17:42

1 Answers1

-2

if you have a multi module project you could add to root gradle buildscript

allprojects {
    repositories {
        jcenter() or mavenCentral()
    }
}
Aegis
  • 5,761
  • 2
  • 33
  • 42
  • OP's question is about two repository and two dependency sections of the same build.gradle file, not about multiple modules. – RaGe Dec 21 '15 at 17:21