tomcat.gradle 2.1 KB

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