build.gradle.kts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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(file("$buildDir/tmp"))
  29. archiveFileName.set("logback-classic-modified.jar")
  30. exclude("/META-INF/services/javax.servlet.ServletContainerInitializer")
  31. doFirst {
  32. configurations.configureEach {
  33. if (name.toLowerCase().endsWith("testruntimeclasspath")) {
  34. val logbackJar = find { it.name.contains("logback-classic") }
  35. from(zipTree(logbackJar))
  36. }
  37. }
  38. }
  39. }
  40. test {
  41. dependsOn(modifyLogbackJar)
  42. dependsOn(setupServer)
  43. doFirst {
  44. // --add-modules is unrecognized on jdk8, ignore it instead of failing
  45. jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
  46. // needed for java 11 to avoid org.jboss.modules.ModuleNotFoundException: java.se
  47. jvmArgs("--add-modules=java.se")
  48. // add offset to default port values
  49. jvmArgs("-Djboss.socket.binding.port-offset=200")
  50. // remove logback-classic from classpath
  51. classpath = classpath.filter {
  52. !it.absolutePath.contains("logback-classic")
  53. }
  54. // add modified copy of logback-classic to classpath
  55. classpath = classpath.plus(files("$buildDir/tmp/logback-classic-modified.jar"))
  56. }
  57. }
  58. }
  59. tasks.withType<Test>().configureEach {
  60. // required on jdk17
  61. jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
  62. jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
  63. }