本文介绍了如何在Gradle构建中为S3支持的Maven存储库使用默认的AWS凭证链?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据等级文档(示例50.27),我们可以使用S3支持带有Gradle 2.4的Maven存储库.但是,文档中给出的唯一示例将显式的AWS凭证传递给S3存储库声明:

According to Gradle documention (Example 50.27), we can use S3 backed Maven repositories with Gradle 2.4. However, the only example given in the docs passes explicit AWS credentials to the S3 repository declaration:

repositories {
    maven {
        url "s3://someS3Bucket/maven2"
        credentials(AwsCredentials) {
            accessKey "someKey"
            secretKey "someSecret"
        }
    }
}

我需要做同样的事情,但是我希望Gradle使用来自AWS JDK的DefaultAWSCredentialsProviderChain,而不是显式凭据.像这样:

I need to do the same thing, but I want Gradle to use the DefaultAWSCredentialsProviderChain, from the AWS JDK, instead of explicit credentials. Something like:

repositories {
    maven {
        url "s3://someS3Bucket/maven2"
        credentials(AwsCredentials) {
            // Default AWS chain here?
        }
    }
}

这样,它将找到我为运行Gradle构建的EC2实例配置的实例配置文件凭据.

This way, it would find the Instance Profile Credentials that I have configured for my EC2 instances where the Gradle build would be running.

有没有办法做到这一点?或者,Gradle是否仅能够使用构建文件中提供的显式凭据针对S3进行身份验证?

Is there a way to accomplish this? Or, is Gradle only capable of authenticating against S3 with explicit credentials given in the build file?

推荐答案

Gradle的最新版本提供了内置方式使用默认提供商链中的凭据,例如:

More recent versions of Gradle provide a built-in way to use credentials from the default provider chain, eg:

maven {
    url "s3://myCompanyBucket/maven2"
    authentication {
       awsIm(AwsImAuthentication) // load from EC2 role or env var
    }
}

这避免了手动创建提供者链实例并传递凭据值的需要.

This avoids the need to manually create an instance of the provider chain and pass in the credential values.

这篇关于如何在Gradle构建中为S3支持的Maven存储库使用默认的AWS凭证链?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 19:40