Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle jettyRun: how does this thing work?

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.

like image 347
Ray Nicholus Avatar asked Oct 23 '11 05:10

Ray Nicholus


2 Answers

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:

  • War and Jetty plugins with http integration tests
  • Right way to do basic web integration testing?

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

like image 96
Benjamin Muschko Avatar answered Nov 17 '22 05:11

Benjamin Muschko


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()
    }
}
like image 2
Sanghyun Lee Avatar answered Nov 17 '22 06:11

Sanghyun Lee