build.gradle.kts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. val bootstrapLibs by configurations.creating {
  10. isCanBeResolved = true
  11. isCanBeConsumed = false
  12. }
  13. val javaagentLibs by configurations.creating
  14. dependencies {
  15. bootstrapLibs(project(":instrumentation-api"))
  16. bootstrapLibs(project(":instrumentation-api-annotation-support"))
  17. bootstrapLibs(project(":javaagent-bootstrap"))
  18. bootstrapLibs(project(":javaagent-instrumentation-api"))
  19. bootstrapLibs("org.slf4j:slf4j-simple")
  20. javaagentLibs(project(":testing:agent-exporter", configuration = "shadow"))
  21. testImplementation(project(":testing-common"))
  22. testImplementation("io.opentelemetry:opentelemetry-api")
  23. }
  24. val javaagentDependencies = dependencies
  25. // collect all bootstrap instrumentation dependencies
  26. project(":instrumentation").subprojects {
  27. val subProj = this
  28. plugins.withId("java") {
  29. if (subProj.name == "bootstrap") {
  30. javaagentDependencies.run {
  31. add(bootstrapLibs.name, project(subProj.path))
  32. }
  33. }
  34. }
  35. }
  36. fun isolateAgentClasses (jars: Iterable<File>): CopySpec {
  37. return copySpec {
  38. jars.forEach {
  39. from(zipTree(it)) {
  40. // important to keep prefix "inst" short, as it is prefixed to lots of strings in runtime mem
  41. into("inst")
  42. rename("""(^.*)\.class$""", "$1.classdata")
  43. // Rename LICENSE file since it clashes with license dir on non-case sensitive FSs (i.e. Mac)
  44. rename("""^LICENSE$""", "LICENSE.renamed")
  45. }
  46. }
  47. }
  48. }
  49. evaluationDependsOn(":testing:agent-exporter")
  50. tasks {
  51. jar {
  52. enabled = false
  53. }
  54. val shadowJar by existing(ShadowJar::class) {
  55. dependsOn(":testing:agent-exporter:shadowJar")
  56. configurations = listOf(bootstrapLibs)
  57. with(isolateAgentClasses(javaagentLibs.files))
  58. archiveClassifier.set("")
  59. manifest {
  60. attributes(
  61. "Main-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent",
  62. "Agent-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent",
  63. "Premain-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent",
  64. "Can-Redefine-Classes" to true,
  65. "Can-Retransform-Classes" to true
  66. )
  67. }
  68. }
  69. afterEvaluate {
  70. withType<Test>().configureEach {
  71. inputs.file(shadowJar.get().archiveFile)
  72. jvmArgs("-Dotel.javaagent.debug=true")
  73. jvmArgs("-javaagent:${shadowJar.get().archiveFile.get().asFile.absolutePath}")
  74. dependsOn(shadowJar)
  75. }
  76. }
  77. // Because shadow does not use default configurations
  78. publishing {
  79. publications {
  80. named<MavenPublication>("maven") {
  81. project.shadow.component(this)
  82. }
  83. }
  84. }
  85. }