We have continuous mode working with -d, but only when I let my main in run exit. Is there any way to terminate a running app on change?
We’ve found such behaviour very useful with Nodemon when developing web services. For example to test the service with dependencies we run a container in a docker-compose setup.
I’d guess your run task should depend on a maybeStop task which stops the app if it’s running (connects to a port, executes a restful stop call, places a stop file in a known location etc).
Your application will need to start in a separate process to the gradle process so that gradle can finalise / exit after starting it. If you’re “holding up” the gradle thread whilst your application is running then continuous mode won’t help you.
The maybeStop task doesn’t exist yet, this will be a custom task created by yourself with your own hand rolled stop functionality (eg REST call, socket connect, MBean invocation etc etc)
I’m sure gretty solves this problem, perhaps a poke through the gretty sources can help
Are you sure Gradle is held up? I posted a small sample app at https://github.com/solsson/gradlemon and from the debug output it looks like changes are successfully picked up in the background, in between the output from the running app.
Thanks for the pointers. I just started using Gradle, with the mission to introduce Java as a complement to our Node.js based services. I had a brief look at the sources for the internal APIs in #2336 and for filewatch.jdk7, and I guess I have a bit of a learning curve. I will fork and give it a try over the coming weeks, at least to understand how a restart can be triggered.
This is probably the shortest example of what it takes to implement your own DeploymentHandle to work with continuous build:
https://github.com/gradle/gradle/issues/2336 is basically needed to expose this as a public thing, so you’re not relying on internal APIs and it’s a little more discoverable/feature complete.
An update… I’ve concluded that even with this in place we would probably not develop Java services the way we do with Node.js. Instead we’d use gradle to generate workspaces for Eclipse/IntelliJ and make projects self-contained in terms of testing.
Docker Compose is invaluable for testing our Node.js services, which means that we want fast roundtrips on source change inside a container.
In java we’d do like pre-docker: where mocking does not suffice we’ll run 3rd party dependencies (Kafka, RDBMS) in the junit setup. This is a lot easier with Java than with Node, because it’s been done like this for (relative) ages.
We’ll use Gradle for CI/CD. All our build jobs are already encapsulated using Docker, and Gradle is compatible with that already.