build.gradle.kts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
  2. plugins {
  3. id("io.opentelemetry.instrumentation.javaagent-shadowing")
  4. id("otel.java-conventions")
  5. id("otel.publish-conventions")
  6. }
  7. description = "OpenTelemetry Javaagent for testing"
  8. group = "io.opentelemetry.javaagent"
  9. fun isolateSpec(shadowJarTasks: Collection<Jar>): CopySpec = copySpec {
  10. from(shadowJarTasks.map { zipTree(it.archiveFile) }) {
  11. // important to keep prefix "inst" short, as it is prefixed to lots of strings in runtime mem
  12. into("inst")
  13. rename("""(^.*)\.class$""", "$1.classdata")
  14. // Rename LICENSE file since it clashes with license dir on non-case sensitive FSs (i.e. Mac)
  15. rename("""^LICENSE$""", "LICENSE.renamed")
  16. }
  17. }
  18. val shadowInclude by configurations.creating {
  19. isCanBeResolved = true
  20. isCanBeConsumed = false
  21. }
  22. evaluationDependsOn(":testing:agent-exporter")
  23. tasks {
  24. jar.configure {
  25. enabled = false
  26. manifest {
  27. attributes(
  28. "Main-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent",
  29. "Agent-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent",
  30. "Premain-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent",
  31. "Can-Redefine-Classes" to true,
  32. "Can-Retransform-Classes" to true
  33. )
  34. }
  35. }
  36. val shadowJar by existing(ShadowJar::class) {
  37. configurations = listOf(shadowInclude)
  38. archiveClassifier.set("")
  39. dependsOn(":testing:agent-exporter:shadowJar")
  40. with(isolateSpec(listOf(project(":testing:agent-exporter").tasks.getByName<ShadowJar>("shadowJar"))))
  41. manifest.inheritFrom(jar.get().manifest)
  42. }
  43. afterEvaluate {
  44. withType<Test>().configureEach {
  45. inputs.file(shadowJar.get().archiveFile)
  46. jvmArgs("-Dotel.javaagent.debug=true")
  47. jvmArgs("-javaagent:${shadowJar.get().archiveFile.get().asFile.absolutePath}")
  48. dependsOn(shadowJar)
  49. }
  50. }
  51. }
  52. dependencies {
  53. // Dependencies to include without obfuscation.
  54. shadowInclude(project(":javaagent-bootstrap"))
  55. shadowInclude(project(":instrumentation", configuration = "bootstrap"))
  56. testImplementation(project(":testing-common"))
  57. testImplementation("io.opentelemetry:opentelemetry-api")
  58. }
  59. // Because shadow does not use default configurations
  60. publishing {
  61. publications {
  62. named<MavenPublication>("maven") {
  63. project.shadow.component(this)
  64. }
  65. }
  66. }