How to use the default AWS credentials chain for an S3 backed Maven repository in a Gradle build?

后端 未结 3 1182
轮回少年
轮回少年 2021-02-14 13:39

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 credent

3条回答
  •  长发绾君心
    2021-02-14 14:09

    I managed to accomplish the pom.xml generation, as well as the upload to S3, with the following build.gradle:

    apply plugin: 'java'
    apply plugin: 'maven-publish'
    
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.amazonaws:aws-java-sdk:1.10.58'
        }
    }
    
    publishing {
        publications {
            mavenJava(MavenPublication) {
                groupId 'com.acme'
                artifactId 'sample-gradle-dependency'
                version '1.0'
                from components.java
            }
        }
        repositories {      
            maven {
                url "s3://my-bucket/releases"
                credentials(AwsCredentials) {
                    def defaultCredentials = new com.amazonaws.auth.DefaultAWSCredentialsProviderChain().getCredentials()
                    accessKey defaultCredentials.getAWSAccessKeyId()
                    secretKey defaultCredentials.getAWSSecretKey()
                }
            }       
        }   
    }
    

    This one requires apply plugin: maven-publish, which apparently is the new version of apply plugin: maven.

    This one runs with:

    $ gradle publish
    

提交回复
热议问题