Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run jar with parameters in gradle

I want to run a jar file with parameters located at C:/Users/nwuser/FitNesse/fitnesse-standalone.jar in my gradle script. I know how to do it without parameters:

apply plugin: 'java'

task runJar(dependsOn:jar) << {
  javaexec { 
    main="-jar"; args "C:/Users/nwuser/FitNesse/fitnesse-standalone.jar"
  } 
}

But now I want to do something similiar like (if using the console):

java -jar fitnesse-standalone.jar -c "FrontPage?suite&format=text"

How can I apply -c "FrontPage?suite&format=text" inside my gradle script?

Kind regards !

like image 752
Jason Saruulo Avatar asked Apr 15 '15 07:04

Jason Saruulo


People also ask

How do you pass arguments in Gradle?

If the task you want to pass parameters to is of type JavaExec and you are using Gradle 5, for example the application plugin's run task, then you can pass your parameters through the --args=... command line option. For example gradle run --args="foo --bar=true" .


2 Answers

args is an array, so simply supply your arguments as such:

task runJar(dependsOn:jar) << {
  javaexec { 
    main="-jar";
    args = [
            "C:/Users/nwuser/FitNesse/fitnesse-standalone.jar",
            "-c",
            "FrontPage?suite&format=text"
           ]
  } 
}
like image 153
Ori Lentz Avatar answered Oct 21 '22 04:10

Ori Lentz


If you're just trying to run a FitNesse test suite with Gradle, you can add the FitNesse jar to your dependencies:

repositories {
  mavenCentral()
}

dependencies {
  compile 'org.fitnesse:fitnesse:20161106'
}

and define a JavaExec task like so:

task fitnesse(type: JavaExec) {
  classpath = sourceSets.main.runtimeClasspath

  main = 'fitnesseMain.FitNesseMain'

  args '-c', 'FrontPage?suite&format=text'
}

And then run:

$ gradle fitnesse
...
Executing command: FrontPage?suite&format=text
--------
0 Tests,        0 Failures      0.091 seconds.
like image 3
bonh Avatar answered Oct 21 '22 06:10

bonh