Skip to content

Commit 86d898c

Browse files
authored
build: add maven-enforcer-plugin with Java/Maven/plugin-version rules (E2) (#93)
Wires up Track E2 from the v1.6.5->1.7 readiness taskboard. Binds three rules to the validate phase so the build refuses to start when a precondition is broken: - requireJavaVersion: blocks JDK < 17 (the declared baseline). - requireMavenVersion: blocks Maven < 3.8.0 (oldest version the planned central-publishing pipeline supports). - requirePluginVersions: every plugin must declare an explicit non-LATEST / non-RELEASE / non-SNAPSHOT version. Generalises the PR-7.1 exec-plugin drift lesson. Default-lifecycle plugins (clean, install, site, resources, deploy) are now pinned in a new pluginManagement block so requirePluginVersions has nothing to flag. Versions: clean 3.4.0, install 3.1.4, site 3.21.0, resources 3.3.1, deploy 3.1.4. Minimums and versions live in <properties> so they are visible at the top of the file and easy to bump uniformly. Verification: ./mvnw validate -pl . green (Rule 0/1/2 pass), reactor validate green (root + aggregator + children inheriting parent), full suite still green (~50s).
1 parent 4c9d765 commit 86d898c

2 files changed

Lines changed: 104 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ JitPack continue to resolve through the existing coordinates.
3434
excluded by convention (`InternalAnnotationCoverageTest` covers those).
3535
Method-level `@since` backfill for the ~380 public methods in these
3636
packages is intentionally out of scope here and tracked separately.
37+
- **`maven-enforcer-plugin` gate** (Track E2). Binds three rules to the
38+
`validate` phase so the build refuses to start when a precondition is
39+
broken: `requireJavaVersion` (≥ 17 — the declared baseline, catches
40+
accidental JDK 11 / 15 attempts), `requireMavenVersion` (≥ 3.8.0 —
41+
the oldest version the planned central-publishing pipeline supports),
42+
and `requirePluginVersions` (every plugin must declare an explicit
43+
non-`LATEST` / non-`RELEASE` / non-`SNAPSHOT` version — the
44+
generalisation of the PR-7.1 exec-plugin drift lesson).
45+
Default-lifecycle plugins (`clean` / `install` / `site` / `resources` /
46+
`deploy`) are now pinned in a new `<pluginManagement>` block so
47+
`requirePluginVersions` has nothing to flag. Minimums and versions
48+
live in `<properties>` (`enforcer.requireMavenVersion`,
49+
`enforcer.requireJavaVersion`, `maven.enforcer.plugin.version`).
3750
- **Parallel-session stress test** (Track I2). New
3851
`DocumentSessionParallelStressTest` drives 32 independent
3952
`DocumentSession` instances on a fixed-size thread pool through 4

pom.xml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,14 @@
6666

6767
<!-- Build plugins -->
6868
<maven.compiler.plugin.version>3.15.0</maven.compiler.plugin.version>
69+
<maven.enforcer.plugin.version>3.5.0</maven.enforcer.plugin.version>
6970
<maven.javadoc.plugin.version>3.12.0</maven.javadoc.plugin.version>
7071
<maven.surefire.plugin.version>3.5.5</maven.surefire.plugin.version>
7172

73+
<!-- Minimum toolchain (enforced by maven-enforcer-plugin) -->
74+
<enforcer.requireMavenVersion>3.8.0</enforcer.requireMavenVersion>
75+
<enforcer.requireJavaVersion>17</enforcer.requireJavaVersion>
76+
7277
<!-- Binary compatibility baseline (japicmp profile) -->
7378
<japicmp.version>0.23.1</japicmp.version>
7479
<japicmp.baseline>v1.6.5</japicmp.baseline>
@@ -262,6 +267,44 @@
262267
</dependencies>
263268

264269
<build>
270+
<!--
271+
Pin the default-lifecycle plugins (clean / install / site /
272+
resources / deploy) so requirePluginVersions in the enforcer
273+
block below has nothing to flag. Versions match what Maven
274+
3.9.x currently resolves out-of-the-box; the explicit pin
275+
stops a future Maven upgrade from silently shifting the
276+
plugin set we build against.
277+
-->
278+
<pluginManagement>
279+
<plugins>
280+
<plugin>
281+
<groupId>org.apache.maven.plugins</groupId>
282+
<artifactId>maven-clean-plugin</artifactId>
283+
<version>3.4.0</version>
284+
</plugin>
285+
<plugin>
286+
<groupId>org.apache.maven.plugins</groupId>
287+
<artifactId>maven-install-plugin</artifactId>
288+
<version>3.1.4</version>
289+
</plugin>
290+
<plugin>
291+
<groupId>org.apache.maven.plugins</groupId>
292+
<artifactId>maven-site-plugin</artifactId>
293+
<version>3.21.0</version>
294+
</plugin>
295+
<plugin>
296+
<groupId>org.apache.maven.plugins</groupId>
297+
<artifactId>maven-resources-plugin</artifactId>
298+
<version>3.3.1</version>
299+
</plugin>
300+
<plugin>
301+
<groupId>org.apache.maven.plugins</groupId>
302+
<artifactId>maven-deploy-plugin</artifactId>
303+
<version>3.1.4</version>
304+
</plugin>
305+
</plugins>
306+
</pluginManagement>
307+
265308
<plugins>
266309
<!-- Kotlin compatibility / mixed-source support -->
267310
<plugin>
@@ -297,6 +340,54 @@
297340
</configuration>
298341
</plugin>
299342

343+
<!--
344+
Build-time precondition enforcement. Three rules:
345+
* requireJavaVersion: blocks builds on JDK < 17 (the
346+
declared baseline). Catches "works on my Java 21,
347+
silently breaks on the JDK 17 CI matrix" drift.
348+
* requireMavenVersion: blocks Maven < 3.8.0 — the
349+
oldest version that fully supports the resolver
350+
features the central-publishing plugin (Track D3)
351+
needs to ship Maven Central artefacts.
352+
* requirePluginVersions: every plugin must declare an
353+
explicit <version>. Stops the inherited "latest" or
354+
reactor-default drift that broke the v1.6.0 release
355+
(cf. PR-7.1 exec-plugin lesson). Tracked as 1.6.6 E2.
356+
-->
357+
<plugin>
358+
<groupId>org.apache.maven.plugins</groupId>
359+
<artifactId>maven-enforcer-plugin</artifactId>
360+
<version>${maven.enforcer.plugin.version}</version>
361+
<executions>
362+
<execution>
363+
<id>enforce-toolchain-and-plugin-versions</id>
364+
<phase>validate</phase>
365+
<goals>
366+
<goal>enforce</goal>
367+
</goals>
368+
<configuration>
369+
<rules>
370+
<requireMavenVersion>
371+
<version>[${enforcer.requireMavenVersion},)</version>
372+
<message>GraphCompose requires Maven ${enforcer.requireMavenVersion} or newer.</message>
373+
</requireMavenVersion>
374+
<requireJavaVersion>
375+
<version>[${enforcer.requireJavaVersion},)</version>
376+
<message>GraphCompose requires JDK ${enforcer.requireJavaVersion} or newer.</message>
377+
</requireJavaVersion>
378+
<requirePluginVersions>
379+
<banLatest>true</banLatest>
380+
<banRelease>true</banRelease>
381+
<banSnapshots>true</banSnapshots>
382+
<message>Every plugin must declare an explicit non-LATEST/RELEASE version. See PR-7.1 (exec-plugin drift) for the lesson.</message>
383+
</requirePluginVersions>
384+
</rules>
385+
<fail>true</fail>
386+
</configuration>
387+
</execution>
388+
</executions>
389+
</plugin>
390+
300391
<!-- Java compilation -->
301392
<plugin>
302393
<groupId>org.apache.maven.plugins</groupId>

0 commit comments

Comments
 (0)