Gradle runJar quest?

I am trying to complete a task to run my jar file in gradle.

I came up with the following:

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

However, I cannot find the path to the jar file. Any help is greatly appreciated. Thanks!

Misha

EDIT: OK this is pretty weird. This task is performed before compilation, etc.

EDIT: Fixed. The key is in the note doLast {} or, in abbreviated form

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

Misha

+7
java gradle
source share
4 answers

Koppor's answer works great.

From Main.java in src / main / java, the 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 output] 
+9
source share

Are you looking for an application plugin ? It creates a new "run" task that runs the specified java class.

+3
source share

You should be able to use the jar.archivePath variable;

 task runJar(dependsOn:[jar]){ ant.java(jar: jar.archivePath ,fork:true) } 
+2
source share

My best solution:

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

Thanks!

Misha

+1
source share

All Articles