-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
161 lines (125 loc) · 4.93 KB
/
build.gradle.kts
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
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.java.security)
rewrite(libs.openrewrite.recipe.rewrite.migrate.java)
rewrite(libs.openrewrite.recipe.rewrite.recommendations)
rewrite(libs.openrewrite.recipe.rewrite.testing.frameworks)
}
val oldestSupportedJavaVersion: Int = 17
val newestTestedJavaVersion: Int = 21
tasks.updateDaemonJvm {
@Suppress("UnstableApiUsage")
jvmVersion = JavaLanguageVersion.of(newestTestedJavaVersion)
}
java.toolchain.languageVersion.set(JavaLanguageVersion.of(newestTestedJavaVersion))
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 gives too many false positives for
// tests that check nullness at runtime.
options.errorprone.disable("NullAway")
}
tasks.test { useJUnitPlatformEngines() }
listOf(oldestSupportedJavaVersion, newestTestedJavaVersion).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
useJUnitPlatformEngines()
dependsOn(tasks.compileTestJava)
}
tasks.check { dependsOn(jdkTest) }
}
private fun Test.useJUnitPlatformEngines() {
useJUnitPlatform { includeEngines("junit-jupiter", "jqwik") }
}
spotless {
java {
googleJavaFormat(libs.versions.googleJavaFormat.get())
.reflowLongStrings()
.reorderImports(true)
.formatJavadoc(true)
formatAnnotations()
}
kotlin {
ktfmt(libs.versions.ktfmt.get()).kotlinlangStyle()
target("**/*.kt", "**/*.kts")
}
}
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",
"com.github.jbduncan.rewrite.SecurityBestPractices",
)
isExportDatatables = true
configFile = file("$rootDir/config/rewrite.yml")
failOnDryRunResults = true
}
tasks.check { dependsOn(tasks.rewriteDryRun) }
tasks.spotlessApply {
mustRunAfter(tasks.rewriteRun)
}
// TODO: Experiment with Declarative Gradle (https://declarative.gradle.org/)
// TODO: Follow https://github.com/binkley/modern-java-practices
// 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 pre-commit (https://github.com/pre-commit/pre-commit)
// TODO: Use RenovateBot or Dependabot with Gradle's dependency-submission action:
// https://github.com/gradle/actions/blob/main/dependency-submission/README.md
// TODO: Do GitHub releases and upload to Maven Central. See JUnit 5 and junit-pioneer for examples.