tomcat.gradle 1.8 KB

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