Search code examples
spring-bootgradlemicroservices

How can I configure gradle to start and stop spring boot microservices that stay alive after build completion?


I'm developing an application server that relies on two emulators configured as spring boot microservices. We've recently extracted the emulators from the root project into a separate repository, as they're being used by some other projects as well, and this works a little nicer for inter-project maintenance. I would like to be able to run these emulators from the main project root, as opposed to having to check out their repository and run from that directory. We do something like this for our gradle integration tests - we're using ExecFork (https://github.com/psxpaul/gradle-execfork-plugin) to fire up the two processes. The problem here is that the processes die when the build completes.

What I'm looking for is something similar to this, so that I can run e.g. ./gradlew startEmulators and have both emulators check out the specified version and either block the gradle task (taking up the command window, ctrl-c to stop) or outlive the gradle task. The ability to stop them would be handy as well, but that's a would-like rather than a must-have at this point.

I'll take solutions alternative to gradle too, but preferably nothing too complicated - this needs to be something that I can fairly simply blast out instructions for to the dev team


Solution

  • The answer ended up being a little janky, but it works. Basically, it looks like this:

    task runEmu1(type: com.github.psxpaul.task.JavaExecFork) {
         //execfork stuff
    }
    task runEmu2(type: com.github.psxpaul.task.JavaExecFork) {
         //execfork stuff
    }
    task runEmus() {
        dependsOn('runEmu1', 'runEmu2')
        doLast {
            ant.input(message: 'Press enter to shut down emulators')
        }
    }
    

    Runs both emulators in parallel processes, which kill themselves at the end of the build. The build, of course, does not complete until input is provided to ant.input. It monopolizes a terminal window, but I can live with that for now