SanityCheck
SanityCheck

Reputation: 169

Download from a repository and execute the jar as first step in Gradle build

My gradle build file needs to do this: 1. Download a jar file from an Artifactory repo. 2. Execute that jar file with some specific command line arguments.

Is there any code example of how to accomplish this?

Upvotes: 0

Views: 637

Answers (1)

M.Ricciuti
M.Ricciuti

Reputation: 12096

For downloading a jar you can use Ant 'get' task. For executing the jar after it has been downloaded, you can use Gradle 'javaexec' method from Project API.

An example of script that should work:

// A first task to download the needed Jar into target libs directory
task download {
    doLast {
        ant.get(dest: 'libs/lombok-1.18.2.jar', src: 'http://central.maven.org/maven2/org/projectlombok/lombok/1.18.2/lombok-1.18.2.jar')
    }
}

// A second task that executes the Jar , with some parameters
task execJar {
    dependsOn download
    doLast {
        javaexec {
            main = "-jar";
            args = [
                    "libs/lombok-1.18.2.jar",
                    "version"
            ]
        }
    }
}

Upvotes: 1

Related Questions