I added the following code to build.gradle, lifted from the tomcat plugin’s integration testing example here: https://github.com/bmuschko/gradle-tomcat-plugin
task integrationTest(type: Test) {
include '**/*Integration*.*'
doFirst {
jettyRun.daemon = true
jettyRun.execute()
}
doLast {
jettyStop.execute()
}
}
Looks good, but it doesn’t work. It runs the integration tests (mine fail currently), and exits. However jetty is still left running.
ideas?
thanks
bmuschko1
(Benjamin Muschko)
January 18, 2012, 1:35pm
2
Did you set Jetty’s convention properties stopPort and stopKey? They are required parameters for jettyStop to work correctly.
Yes, I have those configured. Still doesn’t shut down jetty. gradle stopJetty isn’t working either…
here is the full build.gradle code concerned with jetty:
[jettyRunWar,jettyStop]*.stopPort = 8081
[jettyRunWar,jettyStop]*.stopKey = ‘stopKey’
test {
exclude ‘**/Integration .*’
}
task integrationTest(type: Test) {
include ‘**/Integration .*’
doFirst {
jettyRun.daemon = true
jettyRun.execute()
}
doLast {
jettyStop.execute()
}
}
haha, i see the problem above
the stopPort and stopKey weren’t configured for jettyStart
thanks Benjamin!
here is the correct code:
[jettyRun, jettyRunWar,jettyStop]*.stopPort = 8081
[jettyRun, jettyRunWar,jettyStop]*.stopKey = 'stopKey'
test {
exclude '**/*Integration*.*'
}
task integrationTest(type: Test, depends:test) {
include '**/*Integration*.*'
doFirst {
jettyRun.daemon = true
jettyRun.execute()
}
doLast {
jettyStop.execute()
}
}
Looking at the source code: https://github.com/gradle/gradle/blob/master/subprojects/jetty/src/main/java/org/gradle/api/plugins/jetty/AbstractJettyRunTask.java
lines 237 through 247:
// start Jetty
server.start();
if (daemon) {
return;
}
if (getStopPort() != null && getStopPort() > 0 && getStopKey() != null) {
Monitor monitor = new Monitor(getStopPort(), getStopKey(), (Server) server.getProxiedObject());
monitor.start();
}
the stopPort and stopKey are ignored when jetty is run with daemon = true
In the case when gradle is not run as daemon as well (gradle --daemon) the jetty container is automatically stopped at the end, but not by jettyStop task