Search code examples
javagradlebuild.gradlee2e-testingend-to-end

Execute gradle task when its dependency is still running


I have to run a jar file and exec npm tests on it, but using gradle tasks. I'm using dependsOn to run the npm test after the jar is running.

These are my gradle tasks:

task runServer1 (type: Exec) {
// Run the jar file
}

task runNpmTest (type: Exec, dependsOn: ':runServer1') {
// Run npm tests
}

The problem is that when I execute gradle runNpmTest gradle stops at runServer1, which makes sense, because the server is still running. But my NPM tests will never run. Any ideas?


Solution

  • It will not work this way, since runServer1 task is still running - it's a process. What you need is to run a server in background - so it won't block the main thread - and then run the tests. This probably should be done in a single task and configured via actions. Please have a look here and here to catch some useful knowledge.