play.gradle 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. plugins {
  2. // using this plugin will launch the server in the background and won't block the tests
  3. id 'com.github.psxpaul.execfork' version '0.1.8'
  4. id 'play'
  5. }
  6. ext {
  7. minJavaVersionForTests = JavaVersion.VERSION_1_8
  8. playHttpPort = 8080
  9. }
  10. def playVersion = "2.6.20"
  11. def scalaVersion = System.getProperty("scala.binary.version", /* default = */ "2.12")
  12. model {
  13. components {
  14. play {
  15. platform play: playVersion, scala: scalaVersion, java: '1.8'
  16. injectedRoutesGenerator = true
  17. }
  18. }
  19. distributions {
  20. playBinary {
  21. contents {
  22. from("conf") {
  23. into "conf"
  24. }
  25. }
  26. }
  27. }
  28. }
  29. repositories {
  30. jcenter()
  31. maven {
  32. name "lightbend-maven-releases"
  33. url "https://repo.lightbend.com/lightbend/maven-release"
  34. }
  35. ivy {
  36. name "lightbend-ivy-release"
  37. url "https://repo.lightbend.com/lightbend/ivy-releases"
  38. layout "ivy"
  39. }
  40. }
  41. apply from: "${rootDir}/gradle/java.gradle"
  42. description = 'Play Integration Tests.'
  43. dependencies {
  44. play "com.typesafe.play:play-guice_$scalaVersion:$playVersion"
  45. play "com.typesafe.play:play-logback_$scalaVersion:$playVersion"
  46. play "com.typesafe.play:filters-helpers_$scalaVersion:$playVersion"
  47. play project(':dd-trace-api')
  48. play deps.opentracing
  49. testCompile project(':dd-trace-api')
  50. testCompile project(':dd-trace-ot')
  51. testCompile project(':dd-java-agent:testing')
  52. testCompile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.6.0'
  53. }
  54. tasks.register("startServer", com.github.psxpaul.task.ExecFork) {
  55. dependsOn project(':dd-java-agent').shadowJar
  56. playHttpPort = randomOpenPort()
  57. if (playHttpPort == -1) {
  58. throw new GradleException("Failed to get random port to start Play")
  59. }
  60. workingDir = "${buildDir}/stage/playBinary"
  61. commandLine = "${workingDir}/bin/playBinary"
  62. stopAfter = test
  63. standardOutput "${buildDir}/reports/server.log"
  64. // these params tells the ExecFork plugin to block on startServer task until the port is opened or the string is seen in the ouput
  65. waitForPort = playHttpPort
  66. waitForOutput = "Listening for HTTP on /127.0.0.1:${playHttpPort}"
  67. timeout = 240
  68. environment = [
  69. 'JAVA_OPTS' : "-javaagent:${project(':dd-java-agent').tasks.shadowJar.archivePath}"
  70. + " -Ddd.writer.type=LoggingWriter" + " -Ddd.service.name=java-app"
  71. + " -Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug"
  72. + " -Dorg.slf4j.simpleLogger.defaultLogLevel=debug"
  73. + " -Dconfig.file=${workingDir}/conf/application.conf -Dhttp.port=${playHttpPort}"
  74. + " -Dhttp.address=127.0.0.1"
  75. ]
  76. dependsOn 'stage'
  77. }
  78. tasks.register("deletePIDFile") {
  79. delete "${buildDir}/stage/playBinary/RUNNING_PID"
  80. }
  81. tasks.withType(Test).configureEach {
  82. // so the test can get this property
  83. jvmArgs "-Ddatadog.smoketest.server.port=${playHttpPort}"
  84. testLogging {
  85. events "started"
  86. }
  87. dependsOn startServer
  88. // clean up the PID file from the server
  89. finalizedBy deletePIDFile
  90. }