build.gradle.kts 2.7 KB

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