为Artifactory配置grails maven身份验证的正确方法是什么?

时间:2014-05-15 05:19:31

标签: maven grails artifactory

使用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尚未更新。

3 个答案:

答案 0 :(得分:4)

我们的商店目前正在使用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权限设置和一般的用户权限。

答案 1 :(得分:3)

在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/

答案 2 :(得分:2)

另一种方法是将以下内容放入〜/ .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"
    }