Gradle jettyRun: how does this thing work?

10,464

Solution 1

It sounds like you want to start Jetty for in-container integration tests. Besides having a look at the source code these two posts should get you started:

The key feature you are looking for, starting Jetty in the background, is jettyRun.daemon = true.

Solution 2

What I'm using for integration test in build.gradle is looks like below. I think this code is simple and intuitive.

test {
    exclude '**/*IntegrationTest*'
}

task integrationTest(type: Test) {
    include '**/*IntegrationTest*'
    doFirst {
        jettyRun.httpPort = 8080    // Port for test
        jettyRun.daemon = true
        jettyRun.execute()
    }
    doLast {
        jettyStop.stopPort = 8091   // Port for stop signal
        jettyStop.stopKey = 'stopKey'
        jettyStop.execute()
    }
}
Share:
10,464
Ray Nicholus
Author by

Ray Nicholus

http://raynicholus.com Author of Beyond jQuery: a book that aims to educate web developers and give them the confidence to abandon the crutch that is jQuery and embrace the power of the web API and JavaScript. Author of "You Don't Need jQuery!": a series of blog posts that blossomed into "Beyond jQuery", which was published in November of 2016. Fine Uploader lead developer. We're hiring @ Widen!

Updated on June 05, 2022

Comments

  • Ray Nicholus
    Ray Nicholus about 2 years

    Normally, I would start Jetty by constructing a Server instance, setting a connector, a handler, and LifeCycleListener, followed by a call to start() on the Server instance. I haven't the foggiest idea how to make this happen with the jettyRun task in Gradle. The documentation is confusing to me, and I have yet to find an example of how this task works, other than page after page of gradle jettyRun.

    This task is appealing to me because it allegedly returns immediately after execution. This is helpful for running Selenium tests after my webapp is running from Jenkins. I tried to do this via a JavaExec task, but this won't work since the JavaExec task does not terminate until the underlying JVM terminates as well.

  • Ray Nicholus
    Ray Nicholus over 12 years
    Ugh, looks like this requires I mess with a bunch of messy XML. I prefer the short java-based launcher I currently use. The Jetty plugin is only convenient for super-simple setups it seems.
  • Darvex
    Darvex almost 11 years
    I'm having trouble using this code, it seems like jettyStop does not work, as after task is completed, jetty is still running, any ideas what might be causing this?
  • Darvex
    Darvex almost 11 years
    I've tried it with different ports, either i've been unlucky, or there's something more to it. Either way, i'll have a look