-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
387 lines (351 loc) · 15.5 KB
/
build.gradle
File metadata and controls
387 lines (351 loc) · 15.5 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import nebula.plugin.release.git.opinion.Strategies
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
plugins {
id "com.diffplug.spotless"
id 'nebula.release'
}
// Required with spotless v6+
// See https://github.com/diffplug/spotless/issues/984 for details
spotless {
predeclareDepsFromBuildscript()
}
// Need to predeclare every configuration used with spotless
spotlessPredeclare {
java {
googleJavaFormat("1.10.0")
}
groovyGradle {
greclipse()
}
}
// Format the root build too.
spotless {
groovyGradle {
target '*.gradle' // default target of groovyGradle
greclipse()
licenseHeaderFile rootProject.file('buildscripts/spotless.license.gradle'), '(import|pluginManagement)'
}
yaml {
target "*.yaml"
licenseHeaderFile rootProject.file('buildscripts/spotless.license.yaml'), '([a-zA-Z]*:)'
}
format 'dockerfile', {
target '*Dockerfile'
licenseHeaderFile rootProject.file('buildscripts/spotless.license.dockerfile'), '(\\s+|FROM)'
}
}
// Configure release mechanism.
// Nebula plugin will not configure if .git doesn't exist, let's allow building on it by stubbing it
// out. This supports building from the zip archive downloaded from GitHub.
def releaseTask
if (file('.git').exists()) {
release {
defaultVersionStrategy = Strategies.getSNAPSHOT()
}
nebulaRelease {
addReleaseBranchPattern(/v\d+\.\d+\.x/)
}
releaseTask = tasks.named("release")
releaseTask.configure {
mustRunAfter("snapshotSetup", "finalSetup")
}
} else {
releaseTask = tasks.register('release')
}
ext.isReleaseVersion = !version.toString().endsWith("-SNAPSHOT")
subprojects {
apply plugin: 'jacoco'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'com.diffplug.spotless'
apply plugin: 'nebula.release'
group = "com.google.cloud.opentelemetry"
// Note: Version now comes from nebula plugin
repositories {
mavenCentral()
mavenLocal()
maven { url "https://repo.spring.io/milestone" }
maven { url "https://repo.spring.io/snapshot" }
}
// Set up java codestyle checking and correction.
plugins.withId("java") {
plugins.apply('com.diffplug.spotless')
// Configure our default module name for maven publishing
archivesBaseName = "${project.name}"
}
// Support for some higher language versions can only be achieved using Toolchains.
// Compatibility matrix at https://docs.gradle.org/current/userguide/compatibility.html#java
// See https://docs.gradle.org/current/userguide/toolchains.html#toolchains
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
// This ensures bytecode compatibility with Java 8 by ensuring that symbols not
// available in Java 8 are not used in the source code.
// This is equivalent of setting --release flag in Java compiler introduced in Java 9.
// Note that the toolchain used is Java 11 - which means Java 11 is required
// to build this project.
compileJava {
it.options.release = 8
}
// Include license check and auto-format support.
spotless {
java {
googleJavaFormat("1.10.0")
licenseHeaderFile rootProject.file('buildscripts/spotless.license.java'), '(package|import|class|// Includes work from:)'
// ignore generated code for spotlessCheck & spotlessApply
targetExclude '**/build/generated/**/*.*'
}
groovyGradle {
target '*.gradle' // default target of groovyGradle
greclipse()
licenseHeaderFile rootProject.file('buildscripts/spotless.license.gradle'), '(import|plugins|description)'
}
yaml {
target "*.yaml"
licenseHeaderFile rootProject.file('buildscripts/spotless.license.yaml'), '([a-zA-Z]*:)'
}
format 'shell', {
target '*.sh'
licenseHeaderFile (rootProject.file('buildscripts/spotless.license.shell'), "([a-zA-Z])")
.skipLinesMatching("#!.+?\$")
}
}
// Make sure test failures include exception error messages for correction.
test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
exceptionFormat = 'full'
}
}
ext {
assertjVersion = '3.22.0'
autoServiceVersion = '1.1.1'
autoValueVersion = '1.11.0'
slf4jVersion = '2.0.16'
googleAuthVersion = '1.27.0'
googleCloudVersion = '2.44.1'
googleTraceVersion = '2.51.0'
googleCloudBomVersion = '26.48.0'
cloudMonitoringVersion = '3.52.0'
openTelemetryBomVersion = '1.49.0'
openTelemetryVersion = '1.49.0'
openTelemetryInstrumentationBomVersion = '2.15.0'
openTelemetryInstrumentationVersion = '2.15.0'
openTelemetrySemconvVersion = '1.32.0'
openTelemetryContribVersion = '1.46.0'
junitVersion = '4.13'
junit5Version = '5.10.0'
mockitoVersion = '5.2.0'
pubSubVersion = '1.133.0'
testContainersVersion = '1.15.3'
wiremockVersion = '2.35.0'
springVersion = '2.7.18'
springWebVersion = '2.4.5'
springOpenFeignVersion = '3.0.0'
springOtelVersion = '1.0.0-M8'
cloudEventsCoreVersion = '2.5.0'
cloudFunctionsFrameworkApiVersion = '1.1.0'
agentLibraries = [
agent: "io.opentelemetry.javaagent:opentelemetry-javaagent:${openTelemetryInstrumentationVersion}",
]
libraries = [
auto_service_annotations : "com.google.auto.service:auto-service-annotations:${autoServiceVersion}",
auto_service : "com.google.auto.service:auto-service:${autoServiceVersion}",
auto_value_annotations : "com.google.auto.value:auto-value-annotations:${autoValueVersion}",
auto_value : "com.google.auto.value:auto-value:${autoValueVersion}",
cloudevents_core : "io.cloudevents:cloudevents-core:${cloudEventsCoreVersion}",
google_auth : "com.google.auth:google-auth-library-oauth2-http:${googleAuthVersion}",
google_cloud_core : "com.google.cloud:google-cloud-core:${googleCloudVersion}",
google_cloud_trace : "com.google.cloud:google-cloud-trace:${googleTraceVersion}",
google_cloud_trace_grpc : "com.google.api.grpc:grpc-google-cloud-trace-v2:${googleTraceVersion}",
google_cloud_monitoring : "com.google.cloud:google-cloud-monitoring:${cloudMonitoringVersion}",
google_cloud_monitoring_grpc : "com.google.cloud:grpc-google-cloud-monitoring-v3:${cloudMonitoringVersion}",
google_cloud_pubsub : "com.google.cloud:google-cloud-pubsub:${pubSubVersion}",
google_cloud_functions_framework : "com.google.cloud.functions:functions-framework-api:${cloudFunctionsFrameworkApiVersion}",
google_cloud_bom : "com.google.cloud:libraries-bom:${googleCloudBomVersion}",
slf4j : "org.slf4j:slf4j-api:${slf4jVersion}",
opentelemetry_api : "io.opentelemetry:opentelemetry-api:${openTelemetryVersion}",
opentelemetry_bom : "io.opentelemetry:opentelemetry-bom:${openTelemetryBomVersion}",
opentelemetry_instrumetation_bom : "io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:${openTelemetryInstrumentationBomVersion}",
opentelemetry_context : "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}",
opentelemetry_sdk : "io.opentelemetry:opentelemetry-sdk:${openTelemetryVersion}",
opentelemetry_sdk_common : "io.opentelemetry:opentelemetry-sdk-common:${openTelemetryVersion}",
opentelemetry_semconv : "io.opentelemetry.semconv:opentelemetry-semconv:${openTelemetrySemconvVersion}",
opentelemetry_semconv_incubating : "io.opentelemetry.semconv:opentelemetry-semconv-incubating:${openTelemetrySemconvVersion}-alpha",
opentelemetry_sdk_metrics : "io.opentelemetry:opentelemetry-sdk-metrics:${openTelemetryVersion}",
opentelemetry_sdk_autoconf : "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:${openTelemetryVersion}",
opentelemetry_autoconfigure_spi : "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:${openTelemetryVersion}",
opentelemetry_agent_extension : "io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${openTelemetryInstrumentationVersion}-alpha",
opentelemetry_otlp_exporter : "io.opentelemetry:opentelemetry-exporter-otlp:${openTelemetryVersion}",
opentelemetry_logging_exporter : "io.opentelemetry:opentelemetry-exporter-logging:${openTelemetryVersion}",
opentelemetry_gcp_resources : "io.opentelemetry.contrib:opentelemetry-gcp-resources:${openTelemetryContribVersion}-alpha",
opentelemetry_gcp_auth_extension : "io.opentelemetry.contrib:opentelemetry-gcp-auth-extension:${openTelemetryContribVersion}-alpha",
spring_boot_starter : "org.springframework.boot:spring-boot-starter:${springVersion}",
spring_boot_starter_web : "org.springframework.boot:spring-boot-starter-web:${springWebVersion}",
spring_boot_starter_actuator : "org.springframework.boot:spring-boot-starter-actuator:${springVersion}",
spring_cloud_starter_openfeign : "org.springframework.cloud:spring-cloud-starter-openfeign:${springOpenFeignVersion}",
spring_cloud_sleuth_otel_autoconf: "org.springframework.cloud:spring-cloud-sleuth-otel-autoconfigure:${springOtelVersion}",
]
testLibraries = [
assertj : "org.assertj:assertj-core:${assertjVersion}",
junit : "junit:junit:${junitVersion}",
junit5 : "org.junit.jupiter:junit-jupiter-api:${junit5Version}",
junit5_runtime : "org.junit.jupiter:junit-jupiter-engine:${junit5Version}",
junit5_params : "org.junit.jupiter:junit-jupiter-params:${junit5Version}",
mockito : "org.mockito:mockito-inline:${mockitoVersion}",
slf4j_simple: "org.slf4j:slf4j-simple:${slf4jVersion}",
opentelemetry_sdk_testing: "io.opentelemetry:opentelemetry-sdk-testing:${openTelemetryVersion}",
test_containers: "org.testcontainers:testcontainers:${testContainersVersion}",
wiremock : "com.github.tomakehurst:wiremock-jre8:${wiremockVersion}",
]
}
task javadocJar(type: Jar) {
archiveClassifier.set('javadoc')
from javadoc
}
task sourcesJar(type: Jar) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}
test {
systemProperty 'mock.server.path', System.getProperty('mock.server.path')
finalizedBy jacocoTestReport
}
jacocoTestReport {
dependsOn test // tests are required to run before generating the report
}
artifacts {
archives javadocJar, sourcesJar
}
java {
withJavadocJar()
withSourcesJar()
}
releaseTask.configure {
finalizedBy(tasks.named('publish'))
}
if (findProperty("release.enabled") == "true") {
publishing {
publications {
maven(MavenPublication) {
if (findProperty("shadowed") != "true") {
from components.java
}
groupId = 'com.google.cloud.opentelemetry'
afterEvaluate {
artifactId = archivesBaseName
if (findProperty("release.qualifier") != null) {
String[] versionParts = version.split('-')
versionParts[0] = "${versionParts[0]}-${findProperty("release.qualifier")}"
version = versionParts.join("-")
}
}
pom {
name = 'OpenTelemetry Operations Java'
url = 'https://github.com/GoogleCloudPlatform/opentelemetry-operations-java'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'com.google.cloud.opentelemetry'
name = 'OpenTelemetry Operations Contributors'
email = 'opentelemetry-team@google.com'
organization = 'Google Inc'
organizationUrl = 'https://cloud.google.com/products/operations'
}
}
scm {
connection = 'scm:git:https://github.com/GoogleCloudPlatform/opentelemetry-operations-java'
developerConnection = 'scm:git:https://github.com/GoogleCloudPlatform/opentelemetry-operations-java'
url = 'https://github.com/GoogleCloudPlatform/opentelemetry-operations-java'
}
afterEvaluate {
// description is not available until evaluated.
description = project.description
}
}
}
}
repositories {
maven {
// Publish using Portal OSSRH Staging API.
// For more information see https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/#publishing-by-using-the-portal-ossrh-staging-api
def ossrhRelease = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
def ossrhSnapshot = "https://central.sonatype.com/repository/maven-snapshots/"
url = isReleaseVersion ? ossrhRelease : ossrhSnapshot
credentials {
username = rootProject.hasProperty('centralPortalUsername') ? rootProject.centralPortalUsername : "Unknown user"
password = rootProject.hasProperty('centralPortalPassword') ? rootProject.centralPortalPassword : "Unknown password"
}
}
}
}
signing {
required false
// Allow using the GPG agent on linux instead of passwords in a .properties file.
if (rootProject.hasProperty('signingUseGpgCmd')) {
useGpgCmd()
}
sign publishing.publications.maven
}
}
}
tasks.register('sonatypeUploadDefaultRepository') {
group = 'Deployment'
description = 'Uploads the artifact repository published by the maven publish plugin to Central Portal so that it is visible in the UI.'
if (!rootProject.hasProperty('centralPortalUsername') || !rootProject.hasProperty('centralPortalPassword')) {
throw new GradleException("Unable to find the username and password. Please check ~/.gradle/gradle.properties file.")
}
// The logic is placed in a doLast block to ensure it runs during the execution phase.
doLast {
// Create authentication string to be used in the bearer token for the API.
// See https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/#manual-api-endpoints
String authString = "${rootProject.centralPortalUsername}:${rootProject.centralPortalPassword}"
// Encode the auth string and construct the bearer token to be passed in the auth header.
String encodedAuthString = Base64.getEncoder().encodeToString(authString.getBytes('UTF-8'))
String centralPortalUploadEndpoint = 'https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/com.google.cloud.opentelemetry?publishing_type=user_managed'
// Make a manual POST request to the Central Portal Endpoint
def client = HttpClient.newHttpClient()
def request = HttpRequest.newBuilder()
.uri(URI.create(centralPortalUploadEndpoint))
.header('Authorization', "Bearer ${encodedAuthString}")
.header('accept', '*/*')
.POST(HttpRequest.BodyPublishers.ofString(''))
.build()
println "Sending POST request to: ${centralPortalUploadEndpoint}"
// The response body will be handled as a String.
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString())
println "Response Status Code: ${response.statusCode()}"
println "Response Body: ${response.body()}"
// Optionally, fail the build if the request was not successful
if (response.statusCode() >= 400) {
throw new GradleException("Deployment failed! Received HTTP status ${response.statusCode()}")
} else {
println "Default repository uploaded successfully! Please visit https://central.sonatype.com/publishing to complete release process."
}
}
}