build.gradle.kts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import java.time.Duration
  2. plugins {
  3. id("idea")
  4. id("com.github.ben-manes.versions")
  5. id("io.github.gradle-nexus.publish-plugin")
  6. id("otel.spotless-conventions")
  7. }
  8. apply(from = "version.gradle.kts")
  9. nexusPublishing {
  10. packageGroup.set("io.opentelemetry")
  11. repositories {
  12. sonatype {
  13. username.set(System.getenv("SONATYPE_USER"))
  14. password.set(System.getenv("SONATYPE_KEY"))
  15. }
  16. }
  17. connectTimeout.set(Duration.ofMinutes(5))
  18. clientTimeout.set(Duration.ofMinutes(5))
  19. transitionCheckOptions {
  20. // We have many artifacts so Maven Central takes a long time on its compliance checks. This sets
  21. // the timeout for waiting for the repository to close to a comfortable 50 minutes.
  22. maxRetries.set(300)
  23. delayBetween.set(Duration.ofSeconds(10))
  24. }
  25. }
  26. description = "OpenTelemetry instrumentations for Java"
  27. if (project.findProperty("skipTests") as String? == "true") {
  28. subprojects {
  29. tasks.withType<Test>().configureEach {
  30. enabled = false
  31. }
  32. }
  33. }
  34. tasks {
  35. val listTestsInPartition by registering {
  36. group = "Help"
  37. description = "List test tasks in given partition"
  38. // total of 4 partitions (see modulo 4 below)
  39. var testPartition = (project.findProperty("testPartition") as String?)?.toInt()
  40. if (testPartition == null) {
  41. throw GradleException("Test partition must be specified")
  42. } else if (testPartition < 0 || testPartition >= 4) {
  43. throw GradleException("Invalid test partition")
  44. }
  45. val partitionTasks = ArrayList<Test>()
  46. var testPartitionCounter = 0
  47. subprojects {
  48. // relying on predictable ordering of subprojects
  49. // (see https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#N14CB4)
  50. // since we are splitting these tasks across different github action jobs
  51. val enabled = testPartitionCounter++ % 4 == testPartition
  52. if (enabled) {
  53. tasks.withType<Test>().configureEach {
  54. partitionTasks.add(this)
  55. }
  56. }
  57. }
  58. doLast {
  59. File("test-tasks.txt").printWriter().use { writer ->
  60. partitionTasks.forEach { task ->
  61. var taskPath = task.project.path + ":" + task.name
  62. // smoke tests are run separately
  63. // :instrumentation:test runs all instrumentation tests
  64. if (taskPath != ":smoke-tests:test" && taskPath != ":instrumentation:test") {
  65. writer.println(taskPath)
  66. }
  67. }
  68. }
  69. }
  70. // disable all tasks to stop build
  71. subprojects {
  72. tasks.configureEach {
  73. enabled = false
  74. }
  75. }
  76. }
  77. }
  78. if (gradle.startParameter.taskNames.any { it.equals("listTestsInPartition") }) {
  79. // disable all tasks to stop build
  80. project.tasks.configureEach {
  81. if (this.name != "listTestsInPartition") {
  82. enabled = false
  83. }
  84. }
  85. }