Reputation: 9956
In Maven there is the settings.xml
file in which I configure repositories (like Maven repository on a Sonatype Nexus server).
In my Gradle project the URL of the Maven repository is configured directly in my build.gradle
file.
What is best practice in Gradle to configure repositories globally and outside the build file?
Upvotes: 3
Views: 1453
Reputation: 27984
I put the following in %GRADLE_USER_HOME%/gradle.properties
nexus.user=somecoolguy
nexus.password=guessme
Then I use this snippet
allprojects {
repositories {
def repoUrls = [
'https://mynexus:8081/nexus/content/groups/foo',
'https://mynexus:8081/nexus/content/groups/bar',
'https://mynexus:8081/nexus/content/groups/baz'
}
repoUrls.each { String repoUrl ->
maven {
url repoUrl
credentials {
username project.properties['nexus.user']
password project.properties['nexus.password']
}
}
}
}
}
You could easliy turn the snippet into a custom plugin and perhaps improve it to
project.hasProperty('nexus.user')
returns falseUpvotes: 3