[GRADLE-2263] Jetty instances running as daemon cannot be shut down Created: 01/May/12  Updated: 25/Jan/17  Resolved: 19/May/16

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 3.0-milestone-1, 3.0-rc-2

Type: Bug
Reporter: Ray Assignee: Stefan Wolf
Resolution: Fixed Votes: 11


 Description   

The abstractJettyRunTask doesn't register a Watcher for the jetty instance when running in daemon mode. When in daemon mode, AbstractJettyRunTask.startJettyInternal() returns just before the watcher is registered. The return should be after the watcher is registered. This behavior prevents a build from being able to run multiple jetty instances because they cannot be stopped.

I've had to use the following configuration on my jettyRunWar tasks to workaround this:

doLast {
  /**
   * THIS IS A WORKAROUND! THE CURRENT VERSION OF THIS TASK DOESN'T START A WATCHER IN DAEMON MODE
   *
   * If starting the monitor fails, it may be because the jetty task was updated to fix this issue
   * When that happens, we shouldn't need the custom task any more
   *
   * Copied From: AbstractJettyRunTask
   */
   if (getStopPort() != null && getStopPort() > 0 && getStopKey() != null) {
      Monitor monitor = new Monitor(getStopPort(), getStopKey(), server.getProxiedObject());
      monitor.start();
   }
}


 Comments   
Comment by David Del Signore [ 02/Aug/12 ]

The workaround doesn't compile; I'm getting:

* What went wrong:
Could not compile build file 'C:\Users\ddelsignore\Projects\hg_repos\gateway\services\build.gradle'.
> startup failed:
  build file 'C:\Users\ddelsignore\Projects\hg_repos\gateway\services\build.gradle': 99: unable to resolve class Monitor
 @ line 99, column 17.
             Monitor monitor = new Monitor(getStopPort(), getStopKey(), server.getProxiedObject());

It looks like the Jetty plugin is not on my classpath:

* What went wrong:
Could not compile build file 'C:\Users\ddelsignore\Projects\hg_repos\gateway\services\build.gradle'.
> startup failed:
  build file 'C:\Users\ddelsignore\Projects\hg_repos\gateway\services\build.gradle': 89: unable to resolve class org.gradle.api.plugins.jetty.util.Monitor
 @ line 89, column 1.
     import org.gradle.api.plugins.jetty.util.Monitor
     ^

What's the best way to resolve this?

Comment by David Del Signore [ 02/Aug/12 ]

Found it - Monitor has been moved to a new package, the correct import is:

import org.gradle.api.plugins.jetty.internal.Monitor

Complete cut & paste solution:

import org.gradle.api.plugins.jetty.internal.Monitor
[jettyRun, jettyRunWar]*.doLast {
  /**
   * THIS IS A WORKAROUND! THE CURRENT VERSION OF THIS TASK DOESN'T START A WATCHER IN DAEMON MODE
   *
   * If starting the monitor fails, it may be because the jetty task was updated to fix this issue
   * When that happens, we shouldn't need the custom task any more
   *
   * Copied From: AbstractJettyRunTask
   */
   if (getStopPort() != null && getStopPort() > 0 && getStopKey() != null) {
      Monitor monitor = new Monitor(getStopPort(), getStopKey(), server.getProxiedObject());
      monitor.start();
   }
}
Comment by Paul Grove [ 14/Oct/13 ]

This seems a fundamental bug that should be fixed it is a blocker for people wanting to run blackbox functional tests against a web application. It's only lucky I found this so we can now get this into our CI build.

Comment by Terence Kent [ 25/Dec/13 ]

I think pretty much everybody using gradle at this point is using the daemon mode, which also means most gradle users using the jetty plugin have to look up this post and apply the work around. Would be great to have this one resolved.

Comment by Michal Moravcik [ 19/Mar/14 ]

I am stuck on the same problem. Problematic instruction is in AbstractJettyRunTask.java on line 241.
Thank you for the workaround though.

Generated at Wed Jun 30 12:17:11 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.