build.gradle.kts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. plugins {
  2. id("otel.javaagent-testing")
  3. }
  4. val testServer by configurations.creating
  5. val appLibrary by configurations.creating
  6. configurations.named("testCompileOnly") {
  7. extendsFrom(appLibrary)
  8. }
  9. dependencies {
  10. appLibrary("org.springframework:spring-webmvc:3.1.0.RELEASE")
  11. testImplementation("javax.servlet:javax.servlet-api:3.1.0")
  12. val arquillianVersion = "1.7.0.Alpha10"
  13. implementation("org.jboss.arquillian.junit5:arquillian-junit5-container:$arquillianVersion")
  14. implementation("org.jboss.arquillian.protocol:arquillian-protocol-servlet:$arquillianVersion")
  15. testImplementation("org.jboss.shrinkwrap:shrinkwrap-impl-base:1.2.6")
  16. testRuntimeOnly("org.wildfly.arquillian:wildfly-arquillian-container-embedded:2.2.0.Final")
  17. testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
  18. testInstrumentation(project(":instrumentation:spring:spring-webmvc-3.1:javaagent"))
  19. testInstrumentation(project(":instrumentation:spring:spring-web-3.1:javaagent"))
  20. // wildfly version used to run tests
  21. testServer("org.wildfly:wildfly-dist:18.0.0.Final@zip")
  22. }
  23. tasks {
  24. // extract wildfly dist, path is used from arquillian.xml
  25. val setupServer by registering(Copy::class) {
  26. from(zipTree(testServer.singleFile))
  27. into(file("build/server/"))
  28. }
  29. // logback-classic contains /META-INF/services/javax.servlet.ServletContainerInitializer
  30. // that breaks deploy on embedded wildfly
  31. // create a copy of logback-classic jar that does not have this file
  32. val modifyLogbackJar by registering(Jar::class) {
  33. destinationDirectory.set(file("$buildDir/tmp"))
  34. archiveFileName.set("logback-classic-modified.jar")
  35. exclude("/META-INF/services/javax.servlet.ServletContainerInitializer")
  36. doFirst {
  37. configurations.configureEach {
  38. if (name.toLowerCase().endsWith("testruntimeclasspath")) {
  39. val logbackJar = find { it.name.contains("logback-classic") }
  40. from(zipTree(logbackJar))
  41. }
  42. }
  43. }
  44. }
  45. val copyDependencies by registering(Copy::class) {
  46. // test looks for spring jars that are bundled inside deployed application from this directory
  47. from(appLibrary).into("$buildDir/app-libs")
  48. }
  49. test {
  50. dependsOn(modifyLogbackJar)
  51. dependsOn(setupServer)
  52. dependsOn(copyDependencies)
  53. doFirst {
  54. // --add-modules is unrecognized on jdk8, ignore it instead of failing
  55. jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
  56. // needed for java 11 to avoid org.jboss.modules.ModuleNotFoundException: java.se
  57. jvmArgs("--add-modules=java.se")
  58. // add offset to default port values
  59. jvmArgs("-Djboss.socket.binding.port-offset=300")
  60. // remove logback-classic from classpath
  61. classpath = classpath.filter {
  62. !it.absolutePath.contains("logback-classic")
  63. }
  64. // add modified copy of logback-classic to classpath
  65. classpath = classpath.plus(files("$buildDir/tmp/logback-classic-modified.jar"))
  66. }
  67. }
  68. }