Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle runJar task?

Tags:

java

gradle

I am trying to make a task to run my Jar file in gradle.

I have come up with the following:

task runJar(dependsOn:[jar]){
  ant.java(jar:,fork:true)
}

However, I am unable to find the path to the jar file. Any help much appreciated. Thank you!

Misha

EDIT: OK this is rather odd. This task runs before compile, etc.???

EDIT: Fixed. The key is in a doLast { } notation, or, in shorthand

task runJar(dependsOn:"jar")<<{
  ant.java(jar:"${libsDir}${File.separator}${archivesBaseName}.jar",fork:true)
}

Misha

like image 400
Миша Кошелев Avatar asked Jun 17 '10 16:06

Миша Кошелев


2 Answers

Koppor's answer works perfectly.

With a Main.java in src/main/java, my build.gradle file looks like

apply plugin: 'java'
apply plugin: 'application'

mainClassName = "Main"

Running it gives:

gradle run                 

:compileJava
:processResources UP-TO-DATE
:classes
:run
[Main.java's output]
like image 125
mmm111mmm Avatar answered Sep 24 '22 13:09

mmm111mmm


Are you looking for the The Application Plugin? It creates a new task "run", which runs the specified java class.

like image 39
koppor Avatar answered Sep 23 '22 13:09

koppor