-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
199 lines (171 loc) · 6.78 KB
/
build.gradle.kts
File metadata and controls
199 lines (171 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.RequestBody.Companion.asRequestBody
import java.time.Duration
import java.util.Base64
plugins {
id("idea")
id("io.github.gradle-nexus.publish-plugin")
id("otel.spotless-conventions")
/* workaround for
What went wrong:
Could not determine the dependencies of task ':smoke-tests-otel-starter:spring-boot-3.2:bootJar'.
> Could not create task ':smoke-tests-otel-starter:spring-boot-3.2:collectReachabilityMetadata'.
> Cannot set the value of task ':smoke-tests-otel-starter:spring-boot-3.2:collectReachabilityMetadata' property 'metadataService' of type org.graalvm.buildtools.gradle.internal.GraalVMReachabilityMetadataService using a provider of type org.graalvm.buildtools.gradle.internal.GraalVMReachabilityMetadataService.
See https://github.com/gradle/gradle/issues/17559#issuecomment-1327991512
*/
id("org.graalvm.buildtools.native") apply false
}
buildscript {
dependencies {
classpath("com.squareup.okhttp3:okhttp:5.1.0")
}
}
apply(from = "version.gradle.kts")
nexusPublishing {
packageGroup.set("io.opentelemetry")
repositories {
// see https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/#configuration
sonatype {
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
username.set(System.getenv("SONATYPE_USER"))
password.set(System.getenv("SONATYPE_KEY"))
}
}
connectTimeout.set(Duration.ofMinutes(5))
clientTimeout.set(Duration.ofMinutes(30))
transitionCheckOptions {
// We have many artifacts so Maven Central takes a long time on its compliance checks. This sets
// the timeout for waiting for the repository to close to a comfortable 50 minutes.
maxRetries.set(300)
delayBetween.set(Duration.ofSeconds(10))
}
}
description = "OpenTelemetry instrumentations for Java"
if (project.findProperty("skipTests") as String? == "true") {
subprojects {
tasks.withType<Test>().configureEach {
enabled = false
}
}
}
if (gradle.startParameter.taskNames.contains("listTestsInPartition")) {
tasks {
val listTestsInPartition by registering {
group = "Help"
description = "List test tasks in given partition"
// total of 4 partitions (see modulo 4 below)
var testPartition = (project.findProperty("testPartition") as String?)?.toInt()
if (testPartition == null) {
throw GradleException("Test partition must be specified")
} else if (testPartition < 0 || testPartition >= 4) {
throw GradleException("Invalid test partition")
}
val partitionTasks = ArrayList<Test>()
var testPartitionCounter = 0
subprojects {
// relying on predictable ordering of subprojects
// (see https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#N14CB4)
// since we are splitting these tasks across different github action jobs
val enabled = testPartitionCounter++ % 4 == testPartition
if (enabled) {
tasks.withType<Test>().configureEach {
partitionTasks.add(this)
}
}
}
doLast {
File("test-tasks.txt").printWriter().use { writer ->
partitionTasks.forEach { task ->
var taskPath = task.project.path + ":" + task.name
// smoke tests are run separately
// :instrumentation:test runs all instrumentation tests
if (taskPath != ":smoke-tests:test" && taskPath != ":instrumentation:test") {
writer.println(taskPath)
}
}
}
}
// disable all tasks to stop build
subprojects {
tasks.configureEach {
enabled = false
}
}
}
}
// disable all tasks to stop build
project.tasks.configureEach {
if (this.name != "listTestsInPartition") {
enabled = false
}
}
}
tasks {
val stableVersion = version.toString().replace("-alpha", "")
val generateFossaConfiguration by registering {
group = "Help"
description = "Generate .fossa.yml configuration file"
doLast {
File(".fossa.yml").printWriter().use { writer ->
writer.println("version: 3")
writer.println()
writer.println("targets:")
writer.println(" only:")
writer.println(" # only scanning the modules which are published")
writer.println(" # (as opposed to internal testing modules")
rootProject.subprojects
.sortedBy { it.findProperty("archivesName") as String? }
.filter { !it.name.startsWith("bom") }
.filter { it.plugins.hasPlugin("maven-publish") }
.forEach {
writer.println(" - type: gradle")
writer.println(" path: ./")
writer.println(" target: '${it.path}'")
}
writer.println()
writer.println("experimental:")
writer.println(" gradle:")
writer.println(" configurations-only:")
writer.println(" # consumer will only be exposed to these dependencies")
writer.println(" - runtimeClasspath")
}
}
}
val generateReleaseBundle by registering(Zip::class) {
dependsOn(getTasksByName("publishAllPublicationToReleaseRepoRepository", true))
from("releaseRepo")
exclude("**/maven-metadata.*")
duplicatesStrategy = DuplicatesStrategy.FAIL
includeEmptyDirs = false
archiveFileName.set("release-bundle-$stableVersion.zip")
}
val uploadReleaseBundle by registering {
dependsOn(generateReleaseBundle)
val username = System.getenv("SONATYPE_USER") ?: throw GradleException("Sonatype user not set")
val password = System.getenv("SONATYPE_KEY") ?: throw GradleException("Sonatype key not set")
val token = Base64.getEncoder().encodeToString("$username:$password".toByteArray())
var query = "?name=opentelemetry-java-instrumentation-$stableVersion"
query += "&publishingType=AUTOMATIC"
doFirst {
val bundle = generateReleaseBundle.get().outputs.files.singleFile
val httpClient = OkHttpClient()
val request = okhttp3.Request.Builder()
.url("https://central.sonatype.com/api/v1/publisher/upload$query")
.post(
okhttp3.MultipartBody.Builder().addFormDataPart(
"bundle",
bundle.name,
bundle.asRequestBody("application/zip".toMediaType())
).build()
)
.header("authorization", "Bearer $token")
.build()
httpClient.newCall(request).execute().use { response ->
if (response.code != 201) throw GradleException("Unexpected response status ${response.code} while uploading the release bundle")
println("Uploaded deployment ${response.body.string()}")
}
}
}
}