
Gradle - Reusing buildscript Repositories
Gradle is a leading build tool. It downloads libraries from the declared repositories. It has a flaw that you have to declare repositories twice (buildscript.repositories
and repositories
) if you are using plugins.
Especially in an enterprise, It is cumbersome to deal as the definition of a repository can be more than a single line or there could be multiple repositories (public/private).
Avoid doing work twice; Define Repository Once and use it all over.
buildscript {
repositories {
maven {
// Define name of repository
name 'myRepository1'
url 'https://repo.mycompany.com/maven'
metadataSources: {
mavenPom()
}
credentials {
username "user"
password "password"
}
}
}
}
Selective Repository
// this line is going to save the effort
repositories.add(buildscript.repositories.getByName('myRepository1'))
All Repository
repositories = buildscript.repositories