How to externalise Maven credentials in Grails 2.4

ⅰ亾dé卋堺 提交于 2019-12-12 07:35:19

问题


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?


回答1:


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"
  } 
}


来源:https://stackoverflow.com/questions/24544432/how-to-externalise-maven-credentials-in-grails-2-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!