Sunday, March 25, 2012

run jetty on dependency resolved war in gradle



Background:
  • test classes(such as selenium tests) are in an independent module(maven project, etc.).
  • have an external dependency(mave, ivy, etc) to war file(s)
  • want to run jetty on dependent war file(s)
Gradle can start up jetty on dependency resolved war file(s).

// Run Jetty on dependency resolved war file
//
// you can run multiple wars with different configuration by
// adding more task definitions.
//
import org.gradle.api.plugins.jetty.JettyRunWar
apply plugin: 'java'
apply plugin: 'jetty'
repositories {
mavenCentral()
}
configurations {
// define custom dependency configuration for war file
myWebApp
}
dependencies {
// add war file dependency to my custom configuration
myWebApp "org.some:my-app:1.0@war"
}
task runMyWebApp(type: JettyRunWar) {
// specify the resolved war file
webApp = configurations.myWebApp.singleFile
// more configuration
httpPort = 8001
contextPath = 'myWebApp'
}
view raw build.gradle hosted with ❤ by GitHub

When you want to run your tests after jetty started, set "daemon=true" and make the test task depends on your new run-war task.


No comments: