build.gradle.kts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. plugins {
  2. id("otel.javaagent-testing")
  3. }
  4. val testServer by configurations.creating
  5. dependencies {
  6. testImplementation("javax:javaee-api:7.0")
  7. testImplementation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-arquillian-testing"))
  8. testRuntimeOnly("org.wildfly.arquillian:wildfly-arquillian-container-embedded:2.2.0.Final")
  9. testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
  10. testInstrumentation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-annotations:javaagent"))
  11. testInstrumentation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-resteasy-3.0:javaagent"))
  12. // wildfly version used to run tests
  13. testServer("org.wildfly:wildfly-dist:18.0.0.Final@zip")
  14. }
  15. tasks {
  16. // extract wildfly dist, path is used from arquillian.xml
  17. val setupServer by registering(Copy::class) {
  18. inputs.files(testServer)
  19. from({
  20. zipTree(testServer.singleFile)
  21. })
  22. into(file("build/server/"))
  23. }
  24. // logback-classic contains /META-INF/services/javax.servlet.ServletContainerInitializer
  25. // that breaks deploy on embedded wildfly
  26. // create a copy of logback-classic jar that does not have this file
  27. val modifyLogbackJar by registering(Jar::class) {
  28. destinationDirectory.set(layout.buildDirectory.dir("tmp"))
  29. archiveFileName.set("logback-classic-modified.jar")
  30. exclude("/META-INF/services/javax.servlet.ServletContainerInitializer")
  31. doFirst {
  32. configurations.configureEach {
  33. if (name.lowercase().endsWith("testruntimeclasspath")) {
  34. val logbackJar = find { it.name.contains("logback-classic") }
  35. logbackJar?.let {
  36. from(zipTree(logbackJar))
  37. }
  38. }
  39. }
  40. }
  41. }
  42. test {
  43. dependsOn(modifyLogbackJar)
  44. dependsOn(setupServer)
  45. doFirst {
  46. // --add-modules is unrecognized on jdk8, ignore it instead of failing
  47. jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
  48. // needed for java 11 to avoid org.jboss.modules.ModuleNotFoundException: java.se
  49. jvmArgs("--add-modules=java.se")
  50. // add offset to default port values
  51. jvmArgs("-Djboss.socket.binding.port-offset=200")
  52. // remove logback-classic from classpath
  53. classpath = classpath.filter {
  54. !it.absolutePath.contains("logback-classic")
  55. }
  56. // add modified copy of logback-classic to classpath
  57. classpath = classpath.plus(files(layout.buildDirectory.file("tmp/logback-classic-modified.jar")))
  58. }
  59. }
  60. }
  61. tasks.withType<Test>().configureEach {
  62. // required on jdk17
  63. jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
  64. jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
  65. jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")
  66. }