Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: how to make JavaExec task use configuration classpath?

Here's the problem: I want to execute some java class with some dependencies from, say, runtime configuration. How can this be done?

task runJava(type: JavaExec, dependsOn:[classes]) {
        main = 'mypackage.MyClass'
        classpath = //what should I write here to provide classes from runtime configuration?
}
like image 298
Sergey Weiss Avatar asked Dec 03 '12 12:12

Sergey Weiss


1 Answers

You will probably want to use the runtime classpath of your Source sets which includes the compiled classes of your project as well as all the runtime dependencies.

task runJava(type: JavaExec, dependsOn:[classes]) {
    main = 'mypackage.MyClass'
    classpath = sourceSets.main.runtimeClasspath
}

In case you want to the get the path of a specific configuration you can do something like this: configurations.getByName('runtime').asPath or shorter configurations.runtime.asPath.

like image 110
Benjamin Muschko Avatar answered Oct 17 '22 21:10

Benjamin Muschko