-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle.kts
177 lines (153 loc) · 6.15 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import com.diffplug.gradle.spotless.SpotlessExtension
import info.solidsoft.gradle.pitest.PitestPluginExtension
import info.solidsoft.gradle.pitest.PitestTask
plugins {
id("com.diffplug.spotless") version "7.0.2"
id("info.solidsoft.pitest") version "1.15.0" apply false
id("com.github.ben-manes.versions") version "0.51.0"
id("net.ltgt.errorprone") version "4.1.0" apply false
}
val errorProneVersion = "2.36.0"
val googleJavaFormatVersion = "1.25.2"
val ktlintVersion = "1.5.0"
val pitestJUnit5PluginVersion = "1.2.1"
val pitestMainVersion = "1.17.4"
val pmdVersion = "7.9.0"
configurations {
register("dependencyUpdates")
}
dependencies {
"dependencyUpdates"("com.google.errorprone:error_prone_core:$errorProneVersion")
"dependencyUpdates"("com.google.googlejavaformat:google-java-format:$googleJavaFormatVersion")
"dependencyUpdates"("com.pinterest.ktlint:ktlint-bom:$ktlintVersion")
"dependencyUpdates"("org.pitest:pitest-junit5-plugin:$pitestJUnit5PluginVersion")
"dependencyUpdates"("org.pitest:pitest:$pitestMainVersion")
"dependencyUpdates"("net.sourceforge.pmd:pmd-core:$pmdVersion")
}
tasks.withType<com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask>().configureEach {
rejectVersionIf {
setOf("rc", "alpha", "beta").any { candidate.version.contains(it, ignoreCase = true) }
}
}
configure<SpotlessExtension> {
kotlin {
target("**/*.kt")
ktlint(ktlintVersion).editorConfigOverride(mapOf("ktlint_standard_trailing-comma-on-call-site" to "disabled"))
}
kotlinGradle {
target("**/*.gradle.kts")
ktlint(ktlintVersion).editorConfigOverride(mapOf("ktlint_standard_trailing-comma-on-call-site" to "disabled"))
}
}
allprojects {
afterEvaluate {
version = "0.6.0-SNAPSHOT"
group = "io.github.davidburstrom.gradle.version-compatibility"
apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
if (plugins.hasPlugin(JavaPlugin::class.java)) {
java {
googleJavaFormat(googleJavaFormatVersion)
licenseHeaderFile(rootProject.file("config/license-header.txt"))
}
}
}
project.tasks.withType<SourceTask>().configureEach {
if (this.name != "spotlessJavaApply") {
dependsOn("spotlessJavaApply")
}
}
if (plugins.hasPlugin(JavaPlugin::class.java)) {
configure<JavaPluginExtension> {
toolchain {
// Could theoretically be version 8, but it's not compatible with
// ErrorProne. Therefore, the JavaCompile release option is used.
languageVersion = JavaLanguageVersion.of(17)
}
}
tasks.withType(JavaCompile::class).configureEach {
options.release = 8
options.compilerArgs.add("-Werror")
}
apply(plugin = "net.ltgt.errorprone")
dependencies {
"errorprone"(
"com.google.errorprone:error_prone_core:$errorProneVersion"
)
}
apply(plugin = "pmd")
configure<PmdExtension> {
toolVersion = pmdVersion
isConsoleOutput = true
/* Disable default rules and provide specific ones. */
ruleSets = listOf()
ruleSetFiles(rootProject.files("config/pmd/rulesets.xml"))
}
apply(plugin = "info.solidsoft.pitest")
configure<PitestPluginExtension> {
pitestVersion = pitestMainVersion
junit5PluginVersion = pitestJUnit5PluginVersion
timestampedReports = false
targetClasses = setOf(
"example.*",
"io.github.davidburstrom.gradle.versioncompatibility.*"
)
threads = 2
failWhenNoMutations = true
mutators = listOf("DEFAULTS")
useClasspathFile = true
mutationThreshold = 100
if (JavaVersion.current() >= JavaVersion.VERSION_17) {
jvmArgs.addAll(
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/java.util=ALL-UNNAMED"
)
}
tasks.named("build").configure {
dependsOn("pitest")
}
}
tasks.named<PitestTask>("pitest").configure {
inputs.property("src", file("src/test"))
onlyIf {
(inputs.properties["src"] as File).exists()
}
/*
* Carry over all system properties defined for test tasks into the Pitest tasks, except for the "junit"
* ones, as they can interfere with test stability.
*/
systemProperties(tasks.getByName<Test>("test").systemProperties.filterKeys { !it.contains("junit") })
/*
* Include a "pitest" system property to be able to run tests differently if necessary. Use sparingly!
*/
systemProperty("pitest", "true")
// Stabilizes test executions, especially in Docker
environment.remove("HOME")
outputs.cacheIf { true }
}
}
}
}
open class VersionVerifier : DefaultTask() {
@Input
lateinit var version: String
@InputFile
lateinit var readme: File
@TaskAction
fun verify() {
if (!version.endsWith("-SNAPSHOT")) {
readme.readLines()
.filter { "version-compatibility" in it && "\"$version\"" !in it }
.forEach {
throw GradleException("Outdated version in README.md, could not find $version in $it")
}
}
}
}
val verifyVersion = tasks.register("verifyVersion", VersionVerifier::class.java) {
version = project.version.toString()
readme = project.file("README.md")
}
tasks.named("build").configure {
dependsOn(verifyVersion)
}