Gradle: how to force JavaExec task to use classpath configuration?

Here's the problem: I want to execute some Java class with some dependencies, for example, on the runtime configuration. How can I do that?

task runJava(type: JavaExec, dependsOn:[classes]) { main = 'mypackage.MyClass' classpath = //what should I write here to provide classes from runtime configuration? } 
+7
source share
1 answer

You probably want to use the runtime class path for 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 } 

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

+16
source

All Articles