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
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]
Are you looking for the The Application Plugin? It creates a new task "run", which runs the specified java class.
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