swisstech.net

tech and photography

Reuse repository definitions in gradle

2014-10-16

A project I’m working on has accumulated a bunch of repositories we need for the build.gradle script and for the build itself. I don’t want to keep everything twice so I thought some re-use is in order. Thanks to the excellent gradle javadocs and api design, it was easy to accomplish. The end result is this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
// add your repositories here
buildscript {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            credentials {
                username 'user'
                password 'pass'
            }
            url 'https://example.com/maven2'
    }
}

// re-use repositories from buildscript
buildscript.repositories.each { repositories.add(it) }