Reputation: 2977
I have some Gradle projects, but I would like to avoid to load credentials explicitly in build.gradle
file.
An example of what I would like to avoid is:
maven {
credentials {
username "$maven_user"
password "$maven_password"
}
url 'https://my-maven-repo'
}
I would like to avoid to have username and password fields in gradle.build
, even if those values can be loaded from the local host for example from ~/.gradle/gradle.properties
.
What I would like to achieve is to load credentials from ~/.m2/settings.xml
and to specify only the maven repository url in gradle.build
.
Is it possible to do that? I did several attempts but it looks like that Gradle ignore the credentials in settings.xml
Upvotes: 3
Views: 7047
Reputation: 16833
Try the Maven Settings Plugin
Set it up like that :
New way :
plugins {
id 'net.linguica.maven-settings' version '0.5'
}
Old way (Gradle 2.0 or earlier) :
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'net.linguica.gradle:maven-settings-plugin:0.5'
}
}
apply plugin: 'net.linguica.maven-settings'
Then simply declare you repositories :
repositories {
maven {
name 'your-repo'
url 'http://.....'
}
}
Assuming in ~/.m2/settings.xml
you have something like :
<servers>
<server>
<id>your-repo</id>
<username>user</username>
<password>pass</password>
</server>
</servers>
Upvotes: 6