Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle task to do processing when external process is "ready"

Tags:

gradle

I would like my gradle task to:

  1. Execute a command (external process to "start my server").
  2. Wait for a certain output from my external process say "Server Is Ready" in the stdout.
  3. Do something in my gradle task (basically to talk to my external task).
  4. When I am done doing my stuff, end the external process by launching another "stop my server" command.
  5. When both commands complete, end the task.

This is like starting a server to run integration tests, but this is not a tomcat/jetty type server, so it needs to be launch from command line and wait for server to be "ready" via the server's stdout.

I am currently able to use the exec task to run my task and get the output. So I think I can probably code in Groovy/Java to achieve what I want.

However, it seems tedious to code this seemingly common pattern. So I am wondering if there's an easier way to solve such problems without too much coding - i.e. is this a common pattern that gradle has a DSL for?

Note that I am a newbie at Gradle, so any advise around this topic would also be appreciated.

like image 323
kctang Avatar asked Dec 21 '12 09:12

kctang


People also ask

What are the 3 phases of the Gradle lifecycle?

Every Gradle build proceeds through three lifecycle phases in precisely the same order. These phases are initialization, configuration, and execution. During the initialization phase, Gradle starts up and locates the build files it must process.

Which are the tasks are performed by Gradle?

The work that Gradle can do on a project is defined by one or more tasks. A task represents some atomic piece of work which a build performs. This might be compiling some classes, creating a JAR, generating Javadoc, or publishing some archives to a repository.

What is a lifecycle task in Gradle?

In Gradle terms this means that you can define tasks and dependencies between tasks. Gradle guarantees that these tasks are executed in the order of their dependencies, and that each task is executed only once. These tasks form a Directed Acyclic Graph.


1 Answers

As far as I know, current version of Gradle (1.4) has no dedicated DSL support for starting up/shutting down external processes. You can implement it in groovy right inside build script, it should not be too difficult.

like image 52
Nikita Skvortsov Avatar answered Oct 04 '22 03:10

Nikita Skvortsov