-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathai.java-conventions.gradle.kts
More file actions
193 lines (166 loc) · 5.77 KB
/
ai.java-conventions.gradle.kts
File metadata and controls
193 lines (166 loc) · 5.77 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
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import java.time.Duration
plugins {
`java-library`
checkstyle
idea
id("ai.errorprone-conventions")
id("ai.spotless-conventions")
id("ai.spotbugs-conventions")
id("org.owasp.dependencycheck")
}
repositories {
mavenCentral()
mavenLocal()
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
// See https://docs.gradle.org/current/userguide/upgrading_version_5.html, Automatic target JVM version
disableAutoTargetJvm()
withJavadocJar()
withSourcesJar()
}
tasks.withType<JavaCompile>().configureEach {
with(options) {
release.set(8)
compilerArgs.add("-Werror")
// We need to support compiling to Java 8.
// Suppress obsolete source/target warning added in JDK 21 while retaining -Werror for everything else.
// This only disables the 'options' lint category (e.g., the obsolete source/target messages).
compilerArgs.add("-Xlint:-options")
}
}
val dependencyManagement by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = false
isVisible = false
}
afterEvaluate {
configurations.configureEach {
if (isCanBeResolved && !isCanBeConsumed) {
extendsFrom(dependencyManagement)
}
}
}
dependencies {
dependencyManagement(platform(project(":dependencyManagement")))
compileOnly("com.google.code.findbugs:jsr305")
compileOnly("com.google.errorprone:error_prone_annotations")
compileOnly("com.github.spotbugs:spotbugs-annotations")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("ch.qos.logback:logback-classic")
testImplementation("org.slf4j:log4j-over-slf4j")
testImplementation("org.slf4j:jcl-over-slf4j")
testImplementation("org.slf4j:jul-to-slf4j")
}
configurations.configureEach {
resolutionStrategy {
failOnVersionConflict()
preferProjectModules()
}
}
tasks {
named<Jar>("jar") {
// By default Gradle Jar task can put multiple files with the same name
// into a Jar. This may lead to confusion. For example if auto-service
// annotation processing creates files with same name in `scala` and
// `java` directory this would result in Jar having two files with the
// same name in it. Which in turn would result in only one of those
// files being actually considered when that Jar is used leading to very
// confusing failures. Instead we should 'fail early' and avoid building such Jars.
duplicatesStrategy = DuplicatesStrategy.FAIL
}
named<Javadoc>("javadoc") {
with(options as StandardJavadocDocletOptions) {
source = "8"
encoding = "UTF-8"
docEncoding = "UTF-8"
charSet = "UTF-8"
breakIterator(true)
addStringOption("Xdoclint:none", "-quiet")
// non-standard option to fail on warnings, see https://bugs.openjdk.java.net/browse/JDK-8200363
addStringOption("Xwerror", "-quiet")
}
}
withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
// disabling the publication of Gradle Module Metadata
// Because we reconfigure publishing to only include the shadow jar, the Gradle metadata is not correct.
// Since we are fully bundled and have no dependencies, Gradle metadata wouldn't provide any advantage over
// the POM anyways so in practice we shouldn't be losing anything.
withType<GenerateModuleMetadata>().configureEach {
enabled = false
}
}
normalization {
runtimeClasspath {
metaInf {
ignoreAttribute("Implementation-Version")
}
}
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
// All tests must complete within 15 minutes.
// This value is quite big because with lower values (3 mins) we were experiencing large number of false positives
timeout.set(Duration.ofMinutes(15))
reports {
junitXml.isOutputPerTestCase = true
}
testLogging {
showStandardStreams = true
exceptionFormat = TestExceptionFormat.FULL
}
}
afterEvaluate {
val testJavaVersion = gradle.startParameter.projectProperties["testJavaVersion"]?.let(JavaVersion::toVersion)
val useJ9 = gradle.startParameter.projectProperties["testJavaVM"]?.run { this == "openj9" }
?: false
tasks.withType<Test>().configureEach {
if (testJavaVersion != null) {
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(testJavaVersion.majorVersion))
implementation.set(if (useJ9) JvmImplementation.J9 else JvmImplementation.VENDOR_SPECIFIC)
}
)
}
}
}
checkstyle {
configFile = rootProject.file("buildscripts/checkstyle.xml")
// this version should match the version of google_checks.xml used as basis for above configuration
toolVersion = "8.37"
maxWarnings = 0
}
dependencyCheck {
skipConfigurations = listOf("errorprone", "spotbugs", "checkstyle", "annotationProcessor")
failBuildOnCVSS = 0f // fail on any reported CVE
suppressionFile = rootProject.file("buildscripts/dependency-check-suppressions.xml").absolutePath;
nvd.apiKey = System.getenv("NVD_API_KEY")
}
if (!path.startsWith(":smoke-tests")) {
configurations.configureEach {
if (name.lowercase().endsWith("runtimeclasspath")) {
resolutionStrategy.activateDependencyLocking()
}
}
}
// see https://docs.gradle.org/current/userguide/dependency_locking.html#lock_all_configurations_in_one_build_execution
tasks.register("resolveAndLockAll") {
doFirst {
require(gradle.startParameter.isWriteDependencyLocks)
}
doLast {
if (configurations.findByName("runtimeClasspath") != null) {
configurations.named("runtimeClasspath").get().resolve()
}
}
}