maven - 如何在 Grails 2.4 中外部化 Maven 凭据

标签 maven grails grails-2.0 aether

我正在尝试在 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"
  } 
}

关于maven - 如何在 Grails 2.4 中外部化 Maven 凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24544432/

相关文章:

grails - Grails findBy无法与Or/And条件结合使用

grails - 是否可以使用watchedResources 观察Config.groovy 的变化?

maven - 如何在文件名中没有版本的情况下将依赖项包含到 EAR 中

maven - Maven 'system' 范围是可传递的,但 'provided' 不是吗?

java - Tomcat Maven 插件 - 无法编译 Jsp 页面

grails - 如何从命令行覆盖.grails文件夹的默认位置?

grails - 通过引用使用grails/groovy类

spring - 错误: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)

java - maven项目出现错误:FirefoxDriver cannot be resolved to a type

spring - 可以在生产中使用RequestContextHolder.currentRequestAttributes()。request吗?