Gradle jettyRun: how does this thing work?

Usually, I started Jetty by creating an instance of the server, installing the connector, handler LifeCycleListener, and then calling start()the server instance. I have no vague idea how to do this with a task jettyRunin Gradle. The documentation is confusing me, and I have yet to find an example of how this task works, except page after page gradle jettyRun.

This task appeals to me because it supposedly returns immediately after its completion. This is useful for running Selenium tests after my webapp runs on Jenkins. I tried to do this with a task JavaExec, but it won’t work, since the task JavaExecdoes not end until the underlying JVM completes.

+5
source share
2 answers

It looks like you want to run Jetty for integration tests inside the container. In addition to familiarizing yourself with the source code, these two posts should start:

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

+4
source

What I use for the integration test in build.gradleis as follows. 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()
    }
}
+2
source

All Articles