2

I am following the documentation and I tried to create an Exec task:

task karmaTest(type:Exec) {

  // #1 workingDir project.projectDir;

  // #2 workingDir project.projectDir.canonicalPath;

  // #3 workingDir project.projectDir.absolutePath;

  // #4 workingDir project.projectDir.absolutePath.replace(" ", "\\ ");
  commandLine 'karma start --singleRun true --browsers PhantomJS src/test/js/config/karma.conf.js'
}

The task is really simple. It just needs to execute javascript tests using karma.

Output #1:

Caused by: java.io.IOException: Cannot run program "karma start --singleRun true --browsers PhantomJS src/test/js/config/karma.conf.js" (in directory "/home/eianni/Br/Repositories Ciao/git/workflowcobrand/wfc-services"): error=2, No such file or directory

Output #2:

Caused by: java.io.IOException: Cannot run program "karma start --singleRun true --browsers PhantomJS src/test/js/config/karma.conf.js" (in directory "/home/eianni/Br/Repositories Ciao/git/workflowcobrand/wfc-services"): error=2, No such file or directory

Output #3:

Caused by: java.io.IOException: Cannot run program "karma start --singleRun true --browsers PhantomJS src/test/js/config/karma.conf.js" (in directory "/home/eianni/Br/Repositories Ciao/git/workflowcobrand/wfc-services"): error=2, No such file or directory

Output #4:

Caused by: java.io.IOException: Cannot run program "karma start --singleRun true --browsers PhantomJS src/test/js/config/karma.conf.js" (in directory "/home/eianni/Br/Repositories\ Ciao/git/workflowcobrand/wfc-services"): error=2, No such file or directory

As you can see I tried in different ways but I'm still getting the error. I don't think it's the white space since when I renamed If was getting the same error and I also removed workingDir (because the default from docs is project.projectDir but I'm still getting the error).

dierre
  • 7,140
  • 12
  • 75
  • 120

1 Answers1

1

As per the documentation that you linked to, commandLine takes a list of command line arguments, not a single string holding the complete command line. The first item in the list is considered the executable. For convenience, you may want to keep a single String and split it with tokenize():

commandLine 'karma start --singleRun true --browsers PhantomJS src/test/js/config/karma.conf.js'.tokenize()
Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • Yes, I actually corrected it after a while. I'm not used to the syntax so I thought it was a string. Thanks mate. – dierre Aug 29 '13 at 19:17