-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
223 lines (171 loc) · 7.81 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
223 lines (171 loc) · 7.81 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
import net.ltgt.gradle.errorprone.errorprone
plugins {
`java-library`
alias(libs.plugins.ben.manes.versions)
alias(libs.plugins.diffplug.spotless)
alias(libs.plugins.gradlex.reproducible.builds)
alias(libs.plugins.net.ltgt.errorprone)
alias(libs.plugins.openrewrite)
}
group = "com.github.jbduncan.guavagraphutils"
version = "0.1.0-SNAPSHOT"
repositories { mavenCentral() }
dependencies {
api(libs.guava)
testImplementation(libs.jqwik)
testImplementation(libs.assertj)
testImplementation(libs.jgrapht)
testImplementation(libs.jgrapht.guava)
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter)
testRuntimeOnly(libs.junit.platform.launcher)
compileOnly(libs.jspecify)
testCompileOnly(libs.jspecify)
errorprone(libs.errorprone)
errorprone(libs.nullaway)
rewrite(platform(libs.openrewrite.recipe.bom))
rewrite(libs.openrewrite.recipe.rewrite.java.dependencies)
rewrite(libs.openrewrite.recipe.rewrite.migrate.java)
rewrite(libs.openrewrite.recipe.rewrite.testing.frameworks)
}
val oldestSupportedJavaVersion: Int = 17
val newestSupportedJavaVersion: Int = 25
val supportedJavaVersions = listOf(oldestSupportedJavaVersion, 21, newestSupportedJavaVersion)
tasks.updateDaemonJvm {
languageVersion = JavaLanguageVersion.of(newestSupportedJavaVersion)
vendor = JvmVendorSpec.ADOPTIUM
}
java.toolchain.languageVersion.set(JavaLanguageVersion.of(newestSupportedJavaVersion))
tasks.compileJava {
options.release.set(oldestSupportedJavaVersion)
options.compilerArgs = listOf("-Xlint:all,-processing")
options.errorprone {
error("NullAway")
option("NullAway:AnnotatedPackages", "${project.group}")
option("NullAway:CheckOptionalEmptiness", "true")
option("NullAway:HandleTestAssertionLibraries", "true")
}
}
tasks.compileTestJava {
options.release.set(oldestSupportedJavaVersion)
options.compilerArgs = listOf("-parameters")
// Disable NullAway for tests because it generates too many false positives
// for tests that check nullness at runtime.
options.errorprone.disable("NullAway")
}
tasks.test {
// Our tests run on all the JDK versions that we support further down.
// Running them via the normal Test task runs them on one of these JDK
// versions, which is wasteful.
onlyIf { false }
}
supportedJavaVersions.forEach { majorVersion ->
val jdkTest =
tasks.register<Test>("testJdk${majorVersion}Version") {
javaLauncher =
javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(majorVersion)
}
description = "Runs the test suite on JDK $majorVersion"
group = LifecycleBasePlugin.VERIFICATION_GROUP
// Copy inputs from normal Test task.
classpath = sourceSets["test"].runtimeClasspath
testClassesDirs = sourceSets["test"].output.classesDirs
useJUnitPlatform { includeEngines("junit-jupiter", "jqwik") }
dependsOn(tasks.compileTestJava)
}
tasks.check { dependsOn(jdkTest) }
}
spotless {
java {
googleJavaFormat(libs.versions.googleJavaFormat.get())
.reflowLongStrings()
.reorderImports(true)
.formatJavadoc(true)
formatAnnotations()
}
kotlin {
ktfmt(libs.versions.ktfmt.get()).kotlinlangStyle()
}
}
tasks.dependencyUpdates {
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
fun isStable(version: String): Boolean {
val stableKeyword =
listOf("RELEASE", "FINAL", "GA").any { version.contains(it, ignoreCase = true) }
return stableKeyword || regex.matches(version)
}
rejectVersionIf { isStable(currentVersion) && !isStable(candidate.version) }
}
rewrite {
activeRecipe("com.github.jbduncan.rewrite.CodeCleanup")
isExportDatatables = true
configFile = file("$rootDir/config/rewrite.yml")
failOnDryRunResults = true
}
tasks.spotlessApply {
mustRunAfter(tasks.rewriteRun)
}
// TODO: Add Gradle dependency verification:
// https://britter.dev/blog/2025/02/10/gradle-dependency-verification/
// TODO: As I've had to remove org.openrewrite.recipe:rewrite-java-security due to it being a
// commercial OpenRewrite recipe now, adopt FindSecBugs (https://find-sec-bugs.github.io/)
// instead. See how Spotless uses it, and see if Caffeine uses it too.
// TODO: Use static analysis tools:
// - https://github.com/PicnicSupermarket/error-prone-support
// - Custom Refaster templates:
// - Guava Refaster templates
// - Examples on Refaster website
// - Inspirations for new templates from eg templates and ast-grep rules in
// https://github.com/jbduncan/go-containers
// TODO: Adopt errorprone annotations:
// - CheckReturnValue on package-info.java level
// - Var
// See Caffeine's source code for examples and see if any extra errorprone
// checks need to be enabled.
// TODO: try re-enabling NullAway for tests and see what happens
// TODO: Caffeine seems to enable a JSpecify mode for Nullaway. Look into this
// and enable it here.
// TODO: Look into other ways that Caffeine configures Nullaway.
// TODO: Look into ways that Caffeine configures errorprone and Refaster.
// TODO: Adopt hk (https://hk.jdx.dev/), lefthook (github.com/evilmartians/lefthook),
// pre-commit (https://github.com/pre-commit/pre-commit) or another tool for
// git pre-commit hooks
// TODO: jqwik is in maintenance mode, so migrate to kotest property based testing:
// https://kotest.io/docs/proptest/property-based-testing.html
// TODO: Evaluate these Gradle plugins for use:
// - https://docs.gradle.org/current/userguide/jacoco_plugin.html
// - https://github.com/autonomousapps/dependency-analysis-gradle-plugin
// - https://github.com/vanniktech/gradle-dependency-graph-generator-plugin
// - https://github.com/dorongold/gradle-task-tree
// - https://github.com/cashapp/licensee
// - https://github.com/dropbox/dependency-guard
// - https://github.com/spring-io/nohttp
// - https://kordamp.org/kordamp-gradle-plugins
// - https://github.com/freefair/gradle-plugins
// - https://gradleup.com/projects/
// - https://gradlex.org/
// TODO: Enable Gradle build scans: https://scans.gradle.com/
// TODO: Use RenovateBot or Dependabot with Gradle's dependency-submission action:
// https://github.com/gradle/actions/blob/main/dependency-submission/README.md
// TODO: Look into flox (https://github.com/flox/flox) as an alternative to mise for tool management
// TODO: Follow https://github.com/binkley/modern-java-practices
// TODO: Add GitHub Actions CI. Refer to Caffeine's source code for inspiration:
// https://github.com/ben-manes/caffeine/tree/master/.github/workflows
// TODO: Adopt OpenSSF and CodeQL as per JUnit 5's GitHub Actions workflows
// TODO: Structure Gradle project more idiomatically by following
// https://github.com/jjohannes/idiomatic-gradle
// TODO: Do GitHub releases and upload to Maven Central. See JUnit 5 and junit-pioneer for examples.
// May need these plugins:
// - https://github.com/gradle-nexus/publish-plugin
// - https://github.com/shipkit/shipkit-changelog
// - https://github.com/shipkit/shipkit-auto-version
// - https://github.com/melix/japicmp-gradle-plugin
// TODO: Experiment with Declarative Gradle (https://declarative.gradle.org/)
// TODO: Consider fuzzing with com.code_intelligence.jazzer. Search Caffeine's
// source code for more info.
// TODO: Consider making this project use Java modules. https://gradlex.org/ has
// at least one useful plugin for this.
// TODO: Consider migrating AssertJ to Truth (https://github.com/google/truth) as the
// number of assertions is far fewer whilst satisfying most use cases, making it
// easier to work with.