Jetty plugin jettyStop in daemon mode

I am developing a JS application with Gradle and want to use jetty for serving the files. the gradle file looks like

apply plugin: 'jetty'

httpPort = 8887
stopPort = 8081
stopKey = 'stopKey'

jettyRun {
	daemon = true
	scanIntervalSeconds = 5
	webAppSourceDirectory = file('input')

myTask.dependsOn 'jettyRun'
myTask.finalizedBy 'jettyStop'

jettyStop is called and executes without an error. However, the next run fails since jetty is not stopped. I found this post Jetty plugin, stopKey not working in daemon mode and double checked the jetty plugin source org.gradle.api.plugins.jetty.AbstractJettyRunTask:

          if (daemon) {
          if (getStopPort() != null && getStopPort() > 0 && getStopKey() != null) {
            Monitor monitor = new Monitor(getStopPort(), getStopKey(), (Server) server.getProxiedObject());

So how can I stop jetty in daemon mode? I think that the monitor should always be created.
And is it possible to perform jettyStart only when jetty isn’t running to get rid of the startup time?

Thanks for your effort, Christian

Do you running jetty with task myTask? If so, after a jetty server is started, the server is shut down. Because myTask depends on jettyRun, and myTask itself do nothing and then the task jettyStop is executed.

There is 2 way to run a jetty server as you want.

  • Execute only jettyRun, and if you want to stop the server enter CTRL + C(i.e. stop the process).
  • Launch 2 terminals. One for executing jettyRun, and the other for executing jettyStop when if you want to stop the server.

I didn’t include myTask in my code excerp. Actually, it is not myTask, but bootRun ( a client app in a Spring Boot infrastructure).

Ad 1) Running jettyRun directly will not work, since it is blocking. That’s why the daemon mode is introduced.
Ad 2) I know the two terminal trick, but in my case I would need three terminals, one for starting, one for stopping and one for executing the client app.

Since this is not really comfortable, the daemon mode was introduced and starting works perfect. Jetty gets started and my client task is executed. But since the defect I am mentioning it is not possible to stop Jetty (beside kill), since stopping is not supported in daemon mode. In my opinion the daemon mode is not usable at all because of this limitation.

I am surprised that this is no common problem since this is the typical use case when developing JS apps. Now I understand why grunt and gulp have their place.

Kind regards, Christian

The built in jetty plugin has been superceded by the gretty plugin, a feature rich third party plugin.

There’s a spring boot sample [here] (