build.gradle.kts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. inputs.files(testServer)
  27. from({
  28. zipTree(testServer.singleFile)
  29. })
  30. into(file("build/server/"))
  31. }
  32. // logback-classic contains /META-INF/services/javax.servlet.ServletContainerInitializer
  33. // that breaks deploy on embedded wildfly
  34. // create a copy of logback-classic jar that does not have this file
  35. val modifyLogbackJar by registering(Jar::class) {
  36. destinationDirectory.set(file("$buildDir/tmp"))
  37. archiveFileName.set("logback-classic-modified.jar")
  38. exclude("/META-INF/services/javax.servlet.ServletContainerInitializer")
  39. doFirst {
  40. configurations.configureEach {
  41. if (name.toLowerCase().endsWith("testruntimeclasspath")) {
  42. val logbackJar = find { it.name.contains("logback-classic") }
  43. from(zipTree(logbackJar))
  44. }
  45. }
  46. }
  47. }
  48. val copyDependencies by registering(Copy::class) {
  49. // test looks for spring jars that are bundled inside deployed application from this directory
  50. from(appLibrary).into("$buildDir/app-libs")
  51. }
  52. test {
  53. dependsOn(modifyLogbackJar)
  54. dependsOn(setupServer)
  55. dependsOn(copyDependencies)
  56. doFirst {
  57. // --add-modules is unrecognized on jdk8, ignore it instead of failing
  58. jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
  59. // needed for java 11 to avoid org.jboss.modules.ModuleNotFoundException: java.se
  60. jvmArgs("--add-modules=java.se")
  61. // add offset to default port values
  62. jvmArgs("-Djboss.socket.binding.port-offset=300")
  63. // remove logback-classic from classpath
  64. classpath = classpath.filter {
  65. !it.absolutePath.contains("logback-classic")
  66. }
  67. // add modified copy of logback-classic to classpath
  68. classpath = classpath.plus(files("$buildDir/tmp/logback-classic-modified.jar"))
  69. }
  70. }
  71. }