-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
207 lines (188 loc) · 9.2 KB
/
Copy pathbuild.gradle
File metadata and controls
207 lines (188 loc) · 9.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
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
// Project version: single source of truth is gradle/libs.versions.toml ([versions].everydatabase).
// Captured here (root project scope, where the `libs` catalog accessor is unambiguous) and
// applied to every module below.
def everydatabaseVersion = libs.versions.everydatabase.get()
subprojects {
apply plugin: 'java-library'
apply plugin: 'idea'
apply plugin: 'maven-publish'
group = 'br.com.finalcraft.everydatabase'
version = everydatabaseVersion
java {
withSourcesJar()
// One toolchain for the whole build: launch Gradle with any modern JDK
// (Java 25 recommended - Gradle 9.5 runs on it directly) and this toolchain
// compiles and runs everything, EXCEPT the dual-target compileJava override
// below. Test code always compiles and runs on Java 25 (full modern API).
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}
//This might keep function(parameter variable's Names) on the compiled jar
compileJava.options.compilerArgs.add '-parameters'
compileTestJava.options.compilerArgs.add '-parameters'
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
tasks.withType(Test).configureEach {
testLogging {
events = [TestLogEvent.PASSED, TestLogEvent.FAILED, TestLogEvent.SKIPPED]
exceptionFormat = TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
}
}
repositories {
mavenCentral()
maven { url = 'https://maven.petrus.dev/public' }
}
dependencies {
//Lombok
compileOnly libs.lombok
annotationProcessor libs.lombok
testCompileOnly libs.lombok
testAnnotationProcessor libs.lombok
// Gradle 9 no longer provides the JUnit Platform launcher from its own
// distribution - every test JVM needs it on the runtime classpath.
testRuntimeOnly libs.junit.platform.launcher
}
// Publications are defined per module (each sets its own everydatabase-* artifactId):
// core, libby and manager publish 'components.java'.
publishing {
repositories {
maven {
name = "PetrusRepo"
url = "https://maven.petrus.dev/public"
credentials {
username = System.env.PETRUSMAVEN_ACTOR
password = System.env.PETRUSMAVEN_TOKEN
}
authentication {
basic(BasicAuthentication)
}
}
}
}
}
// ======================================================================
// Dual-target: modern Java source syntax -> Java 8 bytecode (:core, :libby, :manager, :manager-jedis)
//
// Production code is written in modern Java syntax but the published artifacts must run on a Java 8
// JVM. The FinalCraft Jabel fork (an annotation processor) lifts javac's source-level check so the
// Java 25 compiler can emit Java 8 bytecode, while `options.release = 8` keeps the *API* floor honest
// (no Java 9+ library APIs in production code).
//
// Unlike the upstream Jabel (which only rode javac internals up to JDK 17), the fork works on JDK 25,
// so production compiles on the single Java 25 toolchain - no separate JDK 17 compiler pin. Everything
// (Gradle, production compile, test compile, test execution) runs on Java 25.
// ======================================================================
configure([project(':core'), project(':libby'), project(':manager'), project(':manager-jedis')]) {
dependencies {
annotationProcessor libs.jabel
compileOnly libs.jabel
}
compileJava {
sourceCompatibility = 25 // modern *syntax* (IDE hint; Jabel lifts javac's source check)
options.release = 8 // Java 8 *bytecode* and *API* floor
}
}
// ======================================================================
// Doc version stamping - the README install coordinates are derived from the
// project version (single source: gradle/libs.versions.toml), not hand-edited.
//
// ./gradlew stampDocsVersions - rewrite every everydatabase artifact coordinate
// in the READMEs to the current project version
// ./gradlew verifyDocsVersions - fail if any is stale (wired into `check`)
//
// The everydatabase-{core,libby,manager} version (the value that changes every release)
// AND the third-party dependency versions in the README Install table are both stamped
// from the catalog, so neither can silently drift. Dependency versions also flow into
// Libby through the generated DependencyVersions class - see libby/build.gradle.
// ======================================================================
def versionedDocs = [file('README.md')]
// Returns `text` with every everydatabase artifact coordinate set to `ver`.
// Three shapes are covered: Gradle/plain quoted coordinates, Maven <version> tags, and the
// shields.io version badge (badge/version-<ver>-<color>) in the README header.
// The badge <ver> may itself contain hyphens (pre-releases like 1.1.0-rc1), so it is matched
// greedily up to the trailing -<color>[?query]) delimiter instead of stopping at the first hyphen.
def stampEveryDatabaseVersion = { String text, String ver ->
text
.replaceAll(/(["']br\.com\.finalcraft\.everydatabase:everydatabase-[a-z-]+:)[^"']+(["'])/) { all, pre, post -> "${pre}${ver}${post}" }
.replaceAll(/(<artifactId>everydatabase-[a-z-]+<\/artifactId>\s*<version>)[^<]+(<\/version>)/) { all, pre, post -> "${pre}${ver}${post}" }
.replaceAll(/(badge\/version-)[^)]+(-[a-z0-9]+(?:\?[^)]*)?\))/) { all, pre, post -> "${pre}${ver}${post}" }
}
// Third-party dependency versions come from the same catalog. The README's Install table lists them
// per coordinate; keep those cells in sync too, so a catalog bump can't silently leave the docs stale.
// Versions are read straight from the [versions] block (a simple `key = "value"` line), so this needs
// no version-catalog accessor.
def catalogVersions = { ->
def toml = rootProject.file('gradle/libs.versions.toml').getText('UTF-8')
def out = [:]
(toml =~ /(?m)^\s*([A-Za-z0-9_-]+)\s*=\s*"([^"]+)"\s*$/).each { all, k, v -> out[k] = v }
out
}()
// README Install-table coordinate -> its catalog version.
def dependencyDocVersions = [
'com.fasterxml.jackson.core:jackson-databind' : catalogVersions.jackson,
'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml': catalogVersions.jackson,
'org.mongodb:mongodb-driver-sync' : catalogVersions.mongodb,
'com.zaxxer:HikariCP' : catalogVersions.hikaricp,
'com.h2database:h2' : catalogVersions.h2,
'com.mysql:mysql-connector-j' : catalogVersions.mysql,
'org.postgresql:postgresql' : catalogVersions.postgresql,
]
// Rewrites the version cell of each Install-table row, keyed by its coordinate:
// | `<coordinate>`<optional note> | <version> | <scope> |
def stampDependencyVersions = { String text ->
def out = text
dependencyDocVersions.each { coord, ver ->
def rowPattern = '(\\|\\s*`' + java.util.regex.Pattern.quote(coord) + '`[^|\\n]*\\|\\s*)([^|\\s]+)(\\s*\\|)'
out = out.replaceAll(rowPattern) { all, pre, old, post -> "${pre}${ver}${post}" }
}
out
}
tasks.register('stampDocsVersions') {
description = 'Rewrites README artifact coordinates to the current project version.'
group = 'documentation'
def ver = everydatabaseVersion
def docs = versionedDocs
def stamp = stampEveryDatabaseVersion
def stampDeps = stampDependencyVersions
doLast {
docs.findAll { it.exists() }.each { f ->
def original = f.getText('UTF-8')
def stamped = stampDeps(stamp(original, ver))
if (stamped != original) {
f.write(stamped, 'UTF-8')
logger.lifecycle("stampDocsVersions: updated ${rootProject.relativePath(f)} -> ${ver}")
}
}
}
}
tasks.register('verifyDocsVersions') {
description = 'Fails if any README artifact coordinate is out of sync with the project version.'
group = 'verification'
def ver = everydatabaseVersion
def docs = versionedDocs
def stamp = stampEveryDatabaseVersion
def stampDeps = stampDependencyVersions
doLast {
def stale = docs.findAll { it.exists() }
.findAll { def t = it.getText('UTF-8'); stampDeps(stamp(t, ver)) != t }
.collect { rootProject.relativePath(it) }
if (!stale.isEmpty()) {
throw new GradleException(
"README versions are out of sync with the catalog / project version ${ver}: ${stale.join(', ')}. " +
"Run './gradlew stampDocsVersions' to fix.")
}
}
}
// Make `check` (run per module) also verify the docs are in sync.
subprojects {
tasks.matching { it.name == 'check' }.configureEach {
dependsOn rootProject.tasks.named('verifyDocsVersions')
}
}