我正在尝试在 Grails 2.4 项目中从使用 Ivy 迁移到使用 Aether 解析器。
我遇到的问题与外部化凭据有关。与此相关的信息可以在此处的 Grails 手册中找到:http://grails.org/doc/latest/guide/conf.html#dependencyRepositories
似乎没有一种文档化的方法可以像使用 Ivy 一样将使用 Maven 的凭据外部化。
使用 Ivy,我可以将这样的内容放入我的 .grails/settings.groovy
文件中:
grails.project.ivy.authentication = {
credentials {
realm = "My Repo"
host = "repo.mycustomrepo.com"
username = "user"
password = "password"
}
}
要使用 Aether,我被迫将凭证块直接放在我的
BuildConfig.groovy
中,如下所示: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'
])
}
}
不幸的是,这对我来说真的很成问题,因为在我的组织内,我们使用 Artifactory,它被配置为使用我们的 LDAP 凭据。这是一个问题,因为我不想在源代码管理中提交我的凭据。
是否有未记录的解决方案或 Grails 根本不支持它?
最佳答案
使用 id
定义您的仓库:
mavenRepo(id:'myrepo', url:"http://localhost:8085/artifactory/libs-release-local/")
然后使用之前指定的
~/.grails/settings.groovy
在 id
中定义您的凭据:grails.project.dependency.authentication = {
credentials {
id = "myrepo"
username = "foo"
password = "bar"
}
}