build.gradle.kts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
  2. import java.time.Duration
  3. plugins {
  4. `kotlin-dsl`
  5. `maven-publish`
  6. signing
  7. id("com.gradle.plugin-publish")
  8. id("io.github.gradle-nexus.publish-plugin")
  9. }
  10. group = "io.opentelemetry.instrumentation"
  11. apply(from = "../version.gradle.kts")
  12. repositories {
  13. mavenCentral()
  14. gradlePluginPortal()
  15. }
  16. val bbGradlePlugin by configurations.creating
  17. configurations.named("compileOnly") {
  18. extendsFrom(bbGradlePlugin)
  19. }
  20. val byteBuddyVersion = "1.14.17"
  21. val aetherVersion = "1.1.0"
  22. dependencies {
  23. implementation("com.google.guava:guava:33.2.1-jre")
  24. // we need to use byte buddy variant that does not shade asm
  25. implementation("net.bytebuddy:byte-buddy-gradle-plugin:${byteBuddyVersion}") {
  26. exclude(group = "net.bytebuddy", module = "byte-buddy")
  27. }
  28. implementation("net.bytebuddy:byte-buddy-dep:${byteBuddyVersion}")
  29. implementation("org.eclipse.aether:aether-connector-basic:${aetherVersion}")
  30. implementation("org.eclipse.aether:aether-transport-http:${aetherVersion}")
  31. implementation("org.apache.maven:maven-aether-provider:3.3.9")
  32. implementation("com.github.johnrengelman:shadow:8.1.1")
  33. testImplementation("org.assertj:assertj-core:3.26.0")
  34. testImplementation(enforcedPlatform("org.junit:junit-bom:5.10.2"))
  35. testImplementation("org.junit.jupiter:junit-jupiter-api")
  36. testImplementation("org.junit.jupiter:junit-jupiter-params")
  37. testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
  38. }
  39. tasks {
  40. withType<Test>().configureEach {
  41. useJUnitPlatform()
  42. }
  43. withType<JavaCompile>().configureEach {
  44. with(options) {
  45. release.set(8)
  46. }
  47. }
  48. withType(KotlinCompile::class).configureEach {
  49. kotlinOptions {
  50. jvmTarget = "1.8"
  51. }
  52. }
  53. }
  54. gradlePlugin {
  55. website.set("https://opentelemetry.io")
  56. vcsUrl.set("https://github.com/open-telemetry/opentelemetry-java-instrumentation")
  57. plugins {
  58. get("io.opentelemetry.instrumentation.muzzle-generation").apply {
  59. displayName = "Muzzle safety net generation"
  60. description = "https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/muzzle.md"
  61. tags.set(listOf("opentelemetry", "instrumentation", "java"))
  62. }
  63. get("io.opentelemetry.instrumentation.muzzle-check").apply {
  64. displayName = "Checks instrumented libraries against muzzle safety net"
  65. description = "https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/muzzle.md"
  66. tags.set(listOf("opentelemetry", "instrumentation", "java"))
  67. }
  68. }
  69. }
  70. java {
  71. toolchain {
  72. languageVersion.set(JavaLanguageVersion.of(11))
  73. }
  74. withJavadocJar()
  75. withSourcesJar()
  76. }
  77. nexusPublishing {
  78. packageGroup.set("io.opentelemetry")
  79. repositories {
  80. sonatype {
  81. username.set(System.getenv("SONATYPE_USER"))
  82. password.set(System.getenv("SONATYPE_KEY"))
  83. }
  84. }
  85. connectTimeout.set(Duration.ofMinutes(5))
  86. clientTimeout.set(Duration.ofMinutes(5))
  87. }
  88. tasks {
  89. publishPlugins {
  90. enabled = !version.toString().contains("SNAPSHOT")
  91. }
  92. }
  93. afterEvaluate {
  94. publishing {
  95. publications {
  96. named<MavenPublication>("pluginMaven") {
  97. pom {
  98. name.set("OpenTelemetry Instrumentation Gradle Plugins")
  99. description.set("Gradle plugins to assist developing OpenTelemetry instrumentation")
  100. url.set("https://github.com/open-telemetry/opentelemetry-java-instrumentation")
  101. licenses {
  102. license {
  103. name.set("The Apache License, Version 2.0")
  104. url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
  105. }
  106. }
  107. developers {
  108. developer {
  109. id.set("opentelemetry")
  110. name.set("OpenTelemetry")
  111. url.set("https://github.com/open-telemetry/opentelemetry-java-instrumentation/discussions")
  112. }
  113. }
  114. scm {
  115. connection.set("scm:git:git@github.com:open-telemetry/opentelemetry-java-instrumentation.git")
  116. developerConnection.set("scm:git:git@github.com:open-telemetry/opentelemetry-java-instrumentation.git")
  117. url.set("git@github.com:open-telemetry/opentelemetry-java-instrumentation.git")
  118. }
  119. }
  120. }
  121. }
  122. }
  123. }
  124. // Sign only if we have a key to do so
  125. val signingKey: String? = System.getenv("GPG_PRIVATE_KEY")
  126. signing {
  127. setRequired({
  128. // only require signing on CI and when a signing key is present
  129. System.getenv("CI") != null && signingKey != null
  130. })
  131. useInMemoryPgpKeys(signingKey, System.getenv("GPG_PASSWORD"))
  132. }