build.gradle.kts 3.0 KB

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