Search code examples
javagradlebuild.gradlegradle-plugin

Gradle, How to download .zip file from S3


I'm planing to write a custom task as below in gradle to download .zip from the S3

task downloadZipFromS3(type: com.amazonaws.gradle.s3.Download) {
  bucket = "${s3.bucket}"
  key = "${s3.key}"
  file = file("your-local-file.zip")
}

But not getting any concrete gradle plugin to download the zip. If there is any "standard" plugin or any other way to download .zip files from S3 and save in my project dir?


Solution

  • Okay, I got it using traditional S3 maven repo plugin download.

    I've added zip into my gradle classpath as

    testLibs("com.myproject:myproject-test-lib:$TEST_LIB_VERSION")
    

    And from classpath extracted the cached zip to project dir as

    /**
     * Extract the 'test-libs' from classpath to project directory.
     */
    task unzipTestLibs(type: Copy) {
        from zipTree(configurations.testLibs.find { it.name.contains('myproject-test-lib') })
            .matching { include '**/*.jar' }
        into "$projectDir/libs/test-lib"
    }
    

    finally, called this task on

    compileJava.dependsOn(unzipTestLibs)