-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.gradle
More file actions
292 lines (268 loc) · 10.2 KB
/
build.gradle
File metadata and controls
292 lines (268 loc) · 10.2 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
plugins {
//id "com.github.ben-manes.versions" version "0.54.0-SNAPSHOT" apply false
id "com.github.ben-manes.versions" version "0.53.0" apply false
id 'com.diffplug.spotless' version '8.4.0' apply false
id 'se.alipsa.gradle.maven-module' version '0.2.0'
}
description = "Groovy libraries for working with matrix ([][] data)"
def isNonStable = { String v ->
def stableKeyword = ['RELEASE','FINAL','GA'].any { v?.toUpperCase()?.contains(it) }
def regex = /^[0-9,.v-]+(-r)?$/
!stableKeyword && !(v ==~ regex)
}
// Extract leading numeric major: "5.0.0", "v5.0.0", "5.0.0-RC1"
def majorOf = { String v ->
def m = (v ?: "") =~ /(?i)^\D*?(\d+)/
m.find() ? (m.group(1) as int) : -1
}
mavenModules {
// ./gradlew mavenMatrixBomInstall
matrixBom {
pomFile = file('matrix-bom/bom.xml')
mustRunAfterSubprojects()
}
// ./gradlew mavenMatrixAllInstall
matrixAll {
pomFile = file('matrix-bom/pom.xml')
mustRunAfter 'matrixBom'
dependsOnAllPublishedSubprojects() {
exclude group: 'matrix-examples'
}
}
}
allprojects {
plugins.withType(MavenPublishPlugin).configureEach {
project.afterEvaluate {project ->
def projectName = project.name
def projectGroup = project.group.toString()
def projectVersion = project.version.toString()
def publicationCoordinates = "${projectGroup}:${projectName}:${projectVersion}"
def publishMessage = "🚀 Published ${projectName}: ${publicationCoordinates}"
tasks.withType(PublishToMavenLocal).configureEach {
doLast {
println publishMessage
if (projectVersion.contains('-SNAPSHOT')) {
println "- Clearing Grapes cache for ${projectGroup}:${projectName} as it is a SNAPSHOT..."
try {
def userHome = System.getProperty("user.home")
// Grapes default layout: ~/.groovy/grapes/<group>/<module>
def grapeDir = new File(userHome, ".groovy/grapes/${projectGroup}/${projectName}")
if (grapeDir.exists()) {
// recursively delete directory
if (grapeDir.deleteDir()) {
println " 🍇 Cleared Grapes cache for ${projectGroup}:${projectName}"
} else {
println " ⚠️ Found Grapes cache at ${grapeDir} but failed to delete it."
}
} else {
println " 🍇 ${projectGroup}:${projectName} is not cached in Grapes."
}
} catch (Exception e) {
println " ⚠️ Error clearing Grapes cache: ${e.message}"
}
}
}
}
}
}
}
subprojects {
// Compile all groovy code statically by default
//tasks.withType(GroovyCompile).configureEach {
// groovyOptions.configurationScript = rootProject.file('config/groovy/compileStatic.groovy')
//}
plugins.withId('groovy') {
apply plugin: 'codenarc'
codenarc {
toolVersion = libs.versions.codenarc.get()
configFile = rootProject.file('config/codenarc/ruleset.groovy')
reportFormat = 'html'
ignoreFailures = true
}
// Regex matching Groovy 5 arrow switch expressions:
// case 'foo' -> value
// case SomeEnum.VALUE ->
// default -> throw ...
def arrowSwitchPattern = /(?m)^\s*(?:case\b.+?|default)\s*->(?:\s|$)/
def collectArrowSwitchFiles = { File srcDir ->
if (!srcDir.exists()) {
return [] as Set<String>
}
def arrowSwitchFiles = [] as Set<String>
srcDir.eachFileRecurse { File f ->
if (f.name.endsWith('.groovy') && (f.text =~ arrowSwitchPattern)) {
arrowSwitchFiles << srcDir.toPath().relativize(f.toPath()).toString()
}
}
arrowSwitchFiles
}
codenarcMain {
def mainSrcDir = file('src/main/groovy')
def projectPath = project.path
// Auto-exclude files with arrow switch syntax (CodeNarc 3.7 can't parse them)
// TODO: Remove this filter when upgrading to CodeNarc 4.0+
doFirst {
excludes = collectArrowSwitchFiles(mainSrcDir)
if (excludes) {
logger.lifecycle("CodeNarc: skipping ${excludes.size()} Groovy file(s) with arrow switch syntax in ${projectPath} (parser limitation)")
}
}
// Warn about old-style switch syntax per AGENTS.md
// TODO: Change to hard failure once all files are migrated to arrow syntax
def enforcementDir = mainSrcDir
doLast {
if (enforcementDir.exists()) {
def oldStyleFiles = []
enforcementDir.eachFileRecurse { File f ->
if (f.name.endsWith('.groovy')) {
String content = f.text
// Match old-style case with colon (but not URLs like http:// or
// ternary/map colons). Pattern: line starts with case, ends with colon.
if (content =~ /(?m)^\s*case\s+.*[^-]:\s*$/) {
oldStyleFiles << f.path
}
}
}
if (oldStyleFiles) {
logger.warn("WARNING: ${oldStyleFiles.size()} file(s) use old-style switch syntax (case X:) — " +
"migrate to arrow syntax (case X ->) per AGENTS.md:")
oldStyleFiles.each { logger.warn(" - $it") }
}
}
}
}
codenarcTest {
def testSrcDir = file('src/test/groovy')
def projectPath = project.path
source = 'src/test/groovy'
doFirst {
excludes = collectArrowSwitchFiles(testSrcDir)
if (excludes) {
logger.lifecycle("CodeNarc: skipping ${excludes.size()} Groovy test file(s) with arrow switch syntax in ${projectPath} (parser limitation)")
}
}
}
apply plugin: 'com.diffplug.spotless'
spotless {
groovy {
excludeJava()
importOrder('\\#', 'groovy', '', 'se.alipsa', 'java', 'javax')
trimTrailingWhitespace()
endWithNewline()
}
java {
trimTrailingWhitespace()
endWithNewline()
}
groovyGradle {
target '*.gradle'
trimTrailingWhitespace()
endWithNewline()
}
}
}
apply plugin: "com.github.ben-manes.versions"
tasks.matching { it.name == "dependencyUpdates" }.configureEach {
gradleReleaseChannel = "current"
checkForGradleUpdate = false // optional: silence Gradle RC noise
def projectName = project.name
def markerFile = rootProject.layout.buildDirectory
.file("dependencyUpdates/.outdated-${project.name}").get().asFile
outputFormatter = { result ->
def outdated = result.outdated.dependencies
if (outdated) {
markerFile.parentFile.mkdirs()
markerFile.text = outdated.size().toString()
println "${projectName}:"
outdated.each { dep ->
def latest = dep.available.release ?: dep.available.milestone ?: dep.available.integration
println " ${dep.group}:${dep.name} ${dep.version} -> ${latest}"
}
}
}
resolutionStrategy {
componentSelection {
all { s ->
if (isNonStable(s.candidate.version) && !isNonStable(s.currentVersion)) {
s.reject('Release candidate')
}
if (s.candidate.group == 'com.github.haifengl' && majorOf(s.candidate.version) >= 5) {
s.reject('Blocked: Smile >= 5 (needs Java 25)')
}
if (s.candidate.group == 'org.openjfx' && majorOf(s.candidate.version) >= 24) {
s.reject('Blocked: JavaFx >= 24 (Exceeds max version for Java 21)')
}
}
}
}
}
}
// Summary task that runs after all dependencyUpdates tasks complete
tasks.register('dependencyUpdatesSummary') {
description = 'Prints a summary after all dependency update checks'
def markerDir = rootProject.layout.buildDirectory
.dir("dependencyUpdates").get().asFile
dependsOn allprojects.collect { p ->
p.tasks.matching { it.name == 'dependencyUpdates' }
}
doLast {
def markers = markerDir.listFiles()?.findAll { it.name.startsWith('.outdated-') } ?: []
if (markers.isEmpty()) {
println '\n ✅ All dependencies are up-to-date.'
} else {
def total = markers.sum { it.text.trim().toInteger() }
if (total == 1) {
println "\n ⚠️ ${total} dependency update available."
} else {
println "\n ⚠️ ${total} dependency updates available."
}
}
markers.each { it.delete() }
}
}
// Root-level dependencyUpdates lifecycle task (plugin is apply-false on root).
// Running `./gradlew dependencyUpdates` resolves to this task, which delegates
// to all subproject dependencyUpdates tasks and triggers the summary.
tasks.register('dependencyUpdates') {
description = 'Runs dependency update checks for all subprojects'
group = 'Help'
dependsOn subprojects.collect { p ->
p.tasks.matching { it.name == 'dependencyUpdates' }
}
finalizedBy tasks.named('dependencyUpdatesSummary')
}
tasks.register('latestMavenVersions') {
description = 'Lists the latest Maven Central version for each published module'
group = 'Help'
// Resolve all data at configuration time to satisfy configuration cache
def modules = []
subprojects.findAll { it.plugins.hasPlugin('maven-publish') }.each {
modules << [name: it.name, group: it.group.toString(), artifact: it.name]
}
def bomFile = file('matrix-bom/bom.xml')
if (bomFile.exists()) {
def bom = new groovy.xml.XmlSlurper().parse(bomFile)
modules << [name: 'matrix-bom', group: bom.groupId.text(), artifact: bom.artifactId.text()]
}
modules.sort { it.name }
doLast {
def repoBase = 'https://repo1.maven.org/maven2'
modules.each { mod ->
try {
def groupPath = mod.group.replace('.', '/')
def metadataUrl = URI.create("${repoBase}/${groupPath}/${mod.artifact}/maven-metadata.xml").toURL()
def metadata = new groovy.xml.XmlSlurper().parseText(metadataUrl.text)
def latest = metadata.versioning.release.text() ?: metadata.versioning.latest.text()
if (latest) {
println "${mod.name}: ${mod.group}:${mod.artifact}:${latest}"
} else {
println "${mod.name}: no release version found"
}
} catch (FileNotFoundException e) {
println "${mod.name}: not found on Maven Central"
} catch (Exception e) {
println "${mod.name}: error querying Maven Central (${e.message})"
}
}
}
}