Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to externalise Maven credentials in Grails 2.4

I'm trying to migrate from using Ivy to using the Aether resolver in a Grails 2.4 project.

The issue I am having is in relation to externalising the credentials. Info related to this can be found in the Grails manual here: http://grails.org/doc/latest/guide/conf.html#dependencyRepositories

There doesn't seem to be a documented way to externalise the credentials for using Maven the way you could with Ivy.

With Ivy I could place something like this into my .grails/settings.groovy file:

grails.project.ivy.authentication = {
    credentials {
        realm = "My Repo"
        host = "repo.mycustomrepo.com"
        username = "user"
        password = "password"
    }
}

To use Aether, I'm forced to place the credentials block directly in my BuildConfig.groovy like so:

repositories {
    inherits true // Whether to inherit repository definitions from plugins

    grailsPlugins()
    grailsHome()
    mavenLocal()
    grailsCentral()
    mavenCentral()
    mavenRepo("http://repo.mycustomrepo.com") {
      //Add authentication details to repository connection
      auth([
        username: 'user',
        password: 'password'
      ])
    }
}

Unfortunately this is really problematic for me, as within my organisation we use Artifactory which is configured to use our LDAP credentials. This is a problem because I don't want to be committing my credentials in source control.

Is there an undocumented solution for this or does Grails simply not support it?

like image 444
James Xabregas Avatar asked Jul 03 '14 03:07

James Xabregas


1 Answers

Define your repo with an id:

 mavenRepo(id:'myrepo', url:"http://localhost:8085/artifactory/libs-release-local/") 

Then define your credentials in ~/.grails/settings.groovy using the previously specified id:

grails.project.dependency.authentication = {
  credentials {
    id = "myrepo"
    username = "foo"
    password = "bar"
  } 
}
like image 91
Graeme Rocher Avatar answered Oct 22 '22 16:10

Graeme Rocher