build.gradle.kts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. plugins {
  2. id("otel.java-conventions")
  3. id("otel.publish-conventions")
  4. }
  5. description = "OpenTelemetry Javaagent for testing"
  6. group = "io.opentelemetry.javaagent"
  7. val agent by configurations.creating {
  8. isCanBeResolved = true
  9. isCanBeConsumed = false
  10. }
  11. val extensionLibs by configurations.creating {
  12. isCanBeResolved = true
  13. isCanBeConsumed = false
  14. }
  15. dependencies {
  16. extensionLibs(project(":testing:agent-exporter", configuration = "shadow"))
  17. agent(project(":javaagent", configuration = "baseJar"))
  18. testImplementation(project(":testing-common"))
  19. testImplementation("io.opentelemetry:opentelemetry-api")
  20. }
  21. tasks {
  22. jar {
  23. dependsOn(agent)
  24. from(zipTree(agent.singleFile))
  25. from(extensionLibs) {
  26. into("extensions")
  27. }
  28. doFirst {
  29. manifest.from(
  30. zipTree(agent.singleFile).matching {
  31. include("META-INF/MANIFEST.MF")
  32. }.singleFile,
  33. )
  34. }
  35. }
  36. afterEvaluate {
  37. withType<Test>().configureEach {
  38. jvmArgs("-Dotel.javaagent.debug=true")
  39. jvmArgumentProviders.add(JavaagentProvider(jar.flatMap { it.archiveFile }))
  40. }
  41. }
  42. }
  43. class JavaagentProvider(
  44. @InputFile
  45. @PathSensitive(PathSensitivity.RELATIVE)
  46. val agentJar: Provider<RegularFile>,
  47. ) : CommandLineArgumentProvider {
  48. override fun asArguments(): Iterable<String> = listOf(
  49. "-javaagent:${file(agentJar).absolutePath}",
  50. )
  51. }