Use JavaExec
. For example, put the following in build.gradle
task execute(type:JavaExec) { main = mainClass classpath = sourceSets.main.runtimeClasspath }
Run gradle -PmainClass=Boo execute
. You get
$ gradle -PmainClass=Boo execute :compileJava :compileGroovy UP-TO-DATE :processResources UP-TO-DATE :classes :execute I am BOO!
mainClass
is a property passed dynamically on the command line. classpath
set to select the latest classes.
If you do not pass in the mainClass
property, this does not execute as expected.
$ gradle execute FAILURE: Build failed with an exception. * Where: Build file 'xxxx/build.gradle' line: 4 * What went wrong: A problem occurred evaluating root project 'Foo'. > Could not find property 'mainClass' on task ':execute'.
UPDATED from comments:
There is no mvn exec:java
equivalent in gradle, you need to either apply the application plugin or complete the JavaExec task.
First Zero Jan 26 '14 at 6:48 2014-01-26 06:48
source share