build.gradle.kts 4.3 KB

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