tomcat.gradle 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. buildscript {
  2. repositories {
  3. maven { url "https://repo.spring.io/plugins-release" }
  4. }
  5. dependencies {
  6. classpath("org.gradle.api.plugins:gradle-tomcat-plugin:1.2.3")
  7. }
  8. }
  9. apply plugin: 'tomcat'
  10. dependencies {
  11. def tomcatVersion = '7.0.54'
  12. tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
  13. "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
  14. tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
  15. exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
  16. }
  17. }
  18. task integrationTomcatRun(type: org.gradle.api.plugins.tomcat.tasks.TomcatRun) {
  19. onlyIf { !sourceSets.integrationTest.allSource.empty }
  20. buildscriptClasspath = tomcatRun.buildscriptClasspath
  21. classesDirectory = project.sourceSets.main.output.classesDir
  22. contextPath = tomcatRun.contextPath
  23. daemon = true
  24. tomcatClasspath = tomcatRun.tomcatClasspath
  25. webAppClasspath = tomcatRun.webAppClasspath
  26. webAppSourceDirectory = tomcatRun.webAppSourceDirectory
  27. doFirst {
  28. // delay reserving ports to ensure they are still available
  29. def ports = reservePorts(3)
  30. httpPort = ports[0]
  31. ajpPort = ports[1]
  32. stopPort = ports[2]
  33. }
  34. }
  35. task integrationTomcatStop(type: org.gradle.api.plugins.tomcat.tasks.TomcatStop) {
  36. onlyIf { !sourceSets.integrationTest.allSource.empty }
  37. doFirst {
  38. stopPort = integrationTomcatRun.stopPort
  39. }
  40. }
  41. integrationTest {
  42. dependsOn integrationTomcatRun
  43. doFirst {
  44. def host = 'localhost:' + integrationTomcatRun.httpPort
  45. systemProperties['geb.build.baseUrl'] = 'http://'+host+'/' + integrationTomcatRun.contextPath + '/'
  46. systemProperties['geb.build.reportsDir'] = 'build/geb-reports'
  47. }
  48. finalizedBy integrationTomcatStop
  49. }
  50. def reservePorts(int count) {
  51. def sockets = []
  52. for(int i in 1..count) {
  53. sockets << new ServerSocket(0)
  54. }
  55. def result = sockets*.localPort
  56. sockets*.close()
  57. result
  58. }