Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a background job from Gradle

I've created a task starting a remote job like

task mytask(type: Exec) {
    commandLine 'ssh'
    args '-f -l me myserver ./start'.split(' ')
}

and it works, however, it seems to wait for the job to terminate. But it never terminates and it shouldn't.

Doing the same from the command line works: Because of the -f switch the ssh command gets executed in the background.

I've tried to add '>&' /dev/null (csh stdout and stderr redirect) to the command line, but without any success. Also the obvious & did nothing. I also extracted the command line into a script, and it's always the same: Gradle waits for termination.

Solution

I've solved it by using a script and redirecting both stdout and stderr in the script. My problem came from confusing redirections... by passing '>&' /dev/null I redirected the streams on the remote computer, but what was needed was a redirection on the local one (i.e., without putting the redirection operator in quotes).

like image 577
maaartinus Avatar asked Aug 13 '14 20:08

maaartinus


People also ask

How do I run a Gradle test?

Run Gradle testsIn your Gradle project, in the editor, create or select a test to run. From the context menu, select Run <test name>.

How do I run a Gradle test from command line?

Use the command ./gradlew test to run all tests.


2 Answers

The Exec task always waits for termination. To run a background job, use the Ant task 'Exec'

ant.exec(
  executable: 'ssh',
  spawn: true
) {
   arg '-f'
   arg '-l'
   arg 'me'
   arg 'myserver'
   arg './start'
}
like image 61
Tony Baguette Avatar answered Sep 29 '22 23:09

Tony Baguette


The Exec task always waits for termination. To run a background job, you need to write your own task, which could, for example, use the Java ProcessBuilder API.

like image 37
Peter Niederwieser Avatar answered Sep 29 '22 22:09

Peter Niederwieser