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?
}
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With