forked from open-telemetry/opentelemetry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathotel.java-conventions.gradle.kts
More file actions
273 lines (228 loc) · 7.71 KB
/
otel.java-conventions.gradle.kts
File metadata and controls
273 lines (228 loc) · 7.71 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
import io.opentelemetry.gradle.OtelJavaExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins {
`java-library`
checkstyle
eclipse
idea
id("otel.errorprone-conventions")
id("otel.jacoco-conventions")
id("otel.spotless-conventions")
id("org.owasp.dependencycheck")
}
val otelJava = extensions.create<OtelJavaExtension>("otelJava")
base {
// May be set already by a parent project, only set if not.
// TODO(anuraaga): Make this less hacky by creating a "module group" plugin.
if (!archivesName.get().startsWith("opentelemetry-")) {
archivesName.set("opentelemetry-$name")
}
}
// normalize timestamps and file ordering in jars, making the outputs reproducible
// see open-telemetry/opentelemetry-java#4488
tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
withJavadocJar()
withSourcesJar()
}
checkstyle {
configDirectory.set(file("$rootDir/buildscripts/"))
toolVersion = "12.1.0"
isIgnoreFailures = false
configProperties["rootDir"] = rootDir
}
dependencyCheck {
skipConfigurations = mutableListOf(
"errorprone",
"checkstyle",
"annotationProcessor",
"java9AnnotationProcessor",
"moduleAnnotationProcessor",
"testAnnotationProcessor",
"testJpmsAnnotationProcessor",
"animalsniffer",
"spotless996155815", // spotless996155815 is a weird configuration that's only added in jaeger-proto, jaeger-remote-sampler
"js2p",
"jmhAnnotationProcessor",
"jmhBasedTestAnnotationProcessor",
"jmhCompileClasspath",
"jmhRuntimeClasspath",
"jmhRuntimeOnly")
failBuildOnCVSS = 7.0f // fail on high or critical CVE
analyzers.assemblyEnabled = false // not sure why its trying to analyze .NET assemblies
nvd.apiKey = System.getenv("NVD_API_KEY")
}
val testJavaVersion = gradle.startParameter.projectProperties.get("testJavaVersion")?.let(JavaVersion::toVersion)
tasks {
withType<JavaCompile>().configureEach {
with(options) {
release.set(8)
if (name != "jmhCompileGeneratedClasses") {
compilerArgs.addAll(
listOf(
"-Xlint:all",
// We suppress the "try" warning because it disallows managing an auto-closeable with
// try-with-resources without referencing the auto-closeable within the try block.
"-Xlint:-try",
// We suppress the "processing" warning as suggested in
// https://groups.google.com/forum/#!topic/bazel-discuss/_R3A9TJSoPM
"-Xlint:-processing",
// We suppress the "options" warning because it prevents compilation on modern JDKs
"-Xlint:-options",
"-Xlint:-serial",
"-Xlint:-this-escape",
// Fail build on any warning
"-Werror",
),
)
}
encoding = "UTF-8"
if (name.contains("Test")) {
// serialVersionUID is basically guaranteed to be useless in tests
compilerArgs.add("-Xlint:-serial")
}
}
}
withType<Test>().configureEach {
useJUnitPlatform()
if (testJavaVersion != null) {
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(testJavaVersion.majorVersion))
},
)
}
val defaultMaxRetries = if (System.getenv().containsKey("CI")) 2 else 0
val maxTestRetries = gradle.startParameter.projectProperties["maxTestRetries"]?.toInt() ?: defaultMaxRetries
develocity.testRetry {
// You can see tests that were retried by this mechanism in the collected test reports and build scans.
maxRetries.set(maxTestRetries);
}
testLogging {
exceptionFormat = TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
showStandardStreams = true
}
maxHeapSize = "1500m"
}
withType<Javadoc>().configureEach {
exclude("io/opentelemetry/**/internal/**")
with(options as StandardJavadocDocletOptions) {
source = "8"
encoding = "UTF-8"
docEncoding = "UTF-8"
breakIterator(true)
addBooleanOption("html5", true)
addBooleanOption("Xdoclint:all,-missing", true)
}
}
withType<Jar>().configureEach {
inputs.property("moduleName", otelJava.moduleName)
manifest {
attributes(
"Automatic-Module-Name" to otelJava.moduleName,
"Built-By" to System.getProperty("user.name"),
"Built-JDK" to System.getProperty("java.version"),
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
)
}
}
afterEvaluate {
withType<Javadoc>().configureEach {
with(options as StandardJavadocDocletOptions) {
val title = "${project.description}"
docTitle = title
windowTitle = title
}
}
}
}
// Add version information to published artifacts.
plugins.withId("otel.publish-conventions") {
tasks {
register("generateVersionResource") {
val moduleName = otelJava.moduleName
val propertiesDir = moduleName.map { File(layout.buildDirectory.asFile.get(), "generated/properties/${it.replace('.', '/')}") }
val versionProperty = project.version.toString()
inputs.property("project.version", versionProperty)
outputs.dir(propertiesDir)
doLast {
File(propertiesDir.get(), "version.properties").writeText("sdk.version=${versionProperty}")
}
}
}
sourceSets {
main {
output.dir("${layout.buildDirectory.asFile.get()}/generated/properties", "builtBy" to "generateVersionResource")
}
}
}
configurations.configureEach {
resolutionStrategy {
failOnVersionConflict()
preferProjectModules()
}
}
val dependencyManagement by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = false
}
dependencies {
dependencyManagement(platform(project(":dependencyManagement")))
afterEvaluate {
configurations.configureEach {
if (isCanBeResolved && !isCanBeConsumed) {
extendsFrom(dependencyManagement)
}
}
}
compileOnly("com.google.auto.value:auto-value-annotations")
compileOnly("com.google.code.findbugs:jsr305")
annotationProcessor("com.google.guava:guava-beta-checker")
// Workaround for @javax.annotation.Generated
// see: https://github.com/grpc/grpc-java/issues/3633
compileOnly("javax.annotation:javax.annotation-api")
modules {
// checkstyle uses the very old google-collections which causes Java 9 module conflict with
// guava which is also on the classpath
module("com.google.collections:google-collections") {
replacedBy("com.google.guava:guava", "google-collections is now part of Guava")
}
}
}
testing {
suites.withType(JvmTestSuite::class).configureEach {
useJUnitJupiter()
dependencies {
implementation(project(project.path))
implementation(project(":testing-internal"))
compileOnly("com.google.auto.value:auto-value-annotations")
compileOnly("com.google.errorprone:error_prone_annotations")
compileOnly("com.google.code.findbugs:jsr305")
implementation("nl.jqno.equalsverifier:equalsverifier")
implementation("org.mockito:mockito-core")
implementation("org.mockito:mockito-junit-jupiter")
implementation("org.assertj:assertj-core")
implementation("org.awaitility:awaitility")
implementation("org.junit-pioneer:junit-pioneer")
implementation("io.github.netmikey.logunit:logunit-jul")
runtimeOnly("org.slf4j:slf4j-simple")
}
targets {
all {
testTask.configure {
systemProperty("java.util.logging.config.class", "io.opentelemetry.internal.testing.slf4j.JulBridgeInitializer")
}
}
}
}
}