How to use Gradle to download artifacts in a script?


(Phanindra) #1

I’m finally posting here after some research without any findings.

In my deployment script, I’d like to use gradle to download intended artifacts. It could be something like gradle downloadArtifact "groupId:artifactId:version" and the corresponding build.gradle could have repository settings. I’m not sure if such usage is recommended or possible but I really like Gradle’s task management side and I’m just trying to experiment with Gradle while learning it.

Any suggestions?

(Chris Doré) #2

You can create configurations with dependencies that can then be resolved (download the artifacts).

configurations {
dependencies {
    myDownloads 'groupId:artifactId:version'
task processMyDownloads {
    inputs.files configurations.myDownloads
    doLast {
        // do work
        println configurations.myDownloads.join( '\n' )
        configurations.myDownloads.each { downloadedFile ->
            // do something with the File downloadedFile