tomcat.gradle 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.5")
  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. "org.apache.tomcat.embed:tomcat-embed-websocket:${tomcatVersion}"
  15. tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
  16. exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
  17. }
  18. }
  19. task integrationTomcatRun(type: org.gradle.api.plugins.tomcat.tasks.TomcatRun) {
  20. onlyIf { !sourceSets.integrationTest.allSource.empty }
  21. buildscriptClasspath = tomcatRun.buildscriptClasspath
  22. contextPath = tomcatRun.contextPath
  23. daemon = true
  24. tomcatClasspath = tomcatRun.tomcatClasspath
  25. webAppClasspath = tomcatRun.webAppClasspath
  26. webAppSourceDirectory = tomcatRun.webAppSourceDirectory
  27. doFirst {
  28. def mainOutputDir = project.sourceSets.main.output.classesDir
  29. if(mainOutputDir) {
  30. classesDirectory = mainOutputDir
  31. }
  32. // delay reserving ports to ensure they are still available
  33. def ports = reservePorts(3)
  34. httpPort = ports[0]
  35. ajpPort = ports[1]
  36. stopPort = ports[2]
  37. }
  38. }
  39. task integrationTomcatStop(type: org.gradle.api.plugins.tomcat.tasks.TomcatStop) {
  40. onlyIf { !sourceSets.integrationTest.allSource.empty }
  41. doFirst {
  42. stopPort = integrationTomcatRun.stopPort
  43. }
  44. }
  45. integrationTest {
  46. dependsOn integrationTomcatRun
  47. doFirst {
  48. def host = 'localhost:' + integrationTomcatRun.httpPort
  49. systemProperties['geb.build.baseUrl'] = 'http://'+host+'/' + integrationTomcatRun.contextPath + '/'
  50. systemProperties['geb.build.reportsDir'] = 'build/geb-reports'
  51. }
  52. finalizedBy integrationTomcatStop
  53. }
  54. def reservePorts(int count) {
  55. def sockets = []
  56. for(int i in 1..count) {
  57. sockets << new ServerSocket(0)
  58. }
  59. def result = sockets*.localPort
  60. sockets*.close()
  61. result
  62. }