【问题标题】:What is the correct way to configure grails maven authentication to Artifactory?将grails maven身份验证配置到Artifactory的正确方法是什么?
【发布时间】:2014-05-15 05:19:30
【问题描述】:

使用 Maven 解析器为 Artifactory 配置身份验证的正确方法是什么?

目前我正在使用:

grails.project.ivy.authentication = {
    repositories {
        mavenRepo "http://SERVER:8081/artifactory/remote-repos"

    }
    credentials {
        realm = "Artifactory Realm"
        host = "SERVER"
        username = "USER"
        password = "PASSWORD"
    }
}

grails.project.dependency.resolver = "maven" // or ivy

grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits("global") {
        // specify dependency exclusions here; for example, uncomment this to disable ehcache:
        // excludes 'ehcache'
    }
    log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    checksums true // Whether to verify checksums on resolve
    legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility

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

//        mavenLocal()

        mavenRepo id: 'Artifactory', url: "http://SERVER:8081/artifactory/remote-repos"

    }

如果我将解析器更改为“ivy”,则会下载依赖项。

使用 maven 解析器 Artifactory 请求日志显示 401 错误

相关 Grails 文档:http://grails.org/doc/latest/guide/conf.html#dependencyRepositories

也许它还没有为 Maven 更新。

【问题讨论】:

  • 我在使用 grails 2.4.0 时遇到了同样的问题,您找到解决方案了吗?

标签: maven grails artifactory


【解决方案1】:

我们的商店目前使用 Grails 2.3.8,每个开发人员都在我们的主目录中保留一个外部构建配置,其中包含以下内容:

artifactory.username = 'username'
artifactory.password = 'password'
artifactory.repo = 'http://our.artifactory.server.com:8080/artifactory/central'
artifactory.repositoryLocation = "http://our.artifactory.server.com:8080/artifactory/libs-release-local"

这是我们在 BuildConfig.groovy 中配置所有 Grails 项目的方式:

def config = new ConfigSlurper(grailsSettings.grailsEnv).parse(new File("$home/my_build_config.groovy").toURI().toURL())

grails.project.dependency.resolver = "maven"

grails.project.dependency.resolution = {

    inherits("global") {
    }

    log "error"
    checksums true
    legacyResolve false

    repositories {

        String artifactoryUrl = config.artifactory.repo
        mavenRepo(artifactoryUrl) {

            auth([
                    username: config.artifactory.username,
                    password: config.artifactory.password
            ])

            updatePolicy "always"
        }
        mavenLocal()
    }

    dependencies {

        // ...
    }

    plugins {

        // ...
    }
}

如果这不起作用,我建议您查看虚拟存储库的 Artifactory 权限设置和一般用户权限。

【讨论】:

  • 尝试此操作时出现以下错误:groovy.lang.MissingMethodException: No signature of method: groovy.util.ConfigSlurper$_parse_closure5.auth() 适用于参数类型:(java.util .LinkedHashMap) values: [[username:username, password:password]] 可能的解决方案:with(groovy.lang.Closure), wait(), run(), any(), dump(), wait(long)跨度>
  • ConfigSlurper 正在读取的配置文件是什么样的?
  • 现在工作。我将解析器设置为“master”而不是“maven”
  • 如果其他人好奇,看起来 RepositoryConfiguration 类定义了可用于“mavenRepo”闭包的方法(无论如何,从 grails 2.3.11 开始)。
【解决方案2】:

在 BuildConfig.groovy 中,使用:

grails.project.repos.default = "AT"

grails {
    project {
        repos {
            AT {
                url = "http://localhost:8081/artifactory/AT/"
                username = "bob"
                password = "MyUnguessablePassword"
            }
        }
    }
}

doco 有点隐蔽,见:http://grails-plugins.github.io/grails-release/docs/manual/guide/single.html#repositories

一个工作示例位于:http://wordpress.transentia.com.au/wordpress/

【讨论】:

  • v3 doco 说:“下一节中描述的所有配置选项都可以进入您项目的 BuildConfig.groovy 文件或您个人的 ~/.grails/settings.groovy。后者特别有用用于存储凭据,因为文件通常不存储在共享源存储库中,因此可以轻松地保持该信息的机密性。”所以你付你的钱,你可以选择......
【解决方案3】:

另一种方法是将以下内容放入 ~/.grails/settings.groovy

myArtifactory{
    username = 'some_user'
    password = 'some_pass'
}

并且比 maven 存储库配置像

mavenRepo("http://my-artifactory") {
        auth([
                username: grailsSettings.config.myArtifactory.username,
                password: grailsSettings.config.myArtifactory.password
        ])

        updatePolicy "always"
    }

【讨论】:

    猜你喜欢
    • 2019-04-23
    • 1970-01-01
    • 2018-02-08
    • 2014-06-06
    • 2021-07-04
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多