Repository navigation
Conversation
Integrate the Maven 4 BuildContext API to skip JAR creation when no input files have changed since the last build. When forceCreation is false and the JAR file already exists, the plugin now registers and scans the classes directory via BuildContext.registerAndProcessInputs() and skips re-packaging if all inputs are UNMODIFIED. Also signals markSkipExecution() at all skip points (skipIfEmpty, unchanged inputs) so downstream mojos can react accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the ad-hoc hasChangedInputs() check with the BuildContext InputSet aggregation pattern. This correctly registers all class files as inputs, associates them with the JAR output file, and lets the build context handle stale output cleanup when inputs are removed. Previously, inputs were registered via registerAndProcessInputs() but the JAR was never associated as an output — breaking the input→output tracking that enables BuildContext's stale output cleanup. The aggregate() pattern is the correct fit for many-inputs-to-one-output transformations like JAR packaging. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gnodet-bot
left a comment
There was a problem hiding this comment.
Incremental JAR creation via BuildContext — the approach is sound, but the input registration has a pattern mismatch that will cause false rebuilds (or missed rebuilds with custom includes/excludes).
This review was generated by an AI agent, Hermès on behalf of @gnodet.
| InputSet inputSet = buildContext.newInputSet(); | ||
| inputSet.registerInputs(classesDir, List.of("**/**"), List.of()); |
There was a problem hiding this comment.
🔴 Input pattern mismatch. registerInputs() uses hardcoded "**/**" with no excludes, but createArchive() uses getIncludes()/getExcludes() — which at minimum excludes **/package.html by default, and may exclude/include user-configured patterns.
This means:
- A change to
package.html(excluded from JAR) triggers a needless rebuild - With custom
<includes>, changes to files outside the include set still trigger rebuilds - The incremental detection tracks a superset of what actually enters the JAR
| InputSet inputSet = buildContext.newInputSet(); | |
| inputSet.registerInputs(classesDir, List.of("**/**"), List.of()); | |
| InputSet inputSet = buildContext.newInputSet(); | |
| inputSet.registerInputs(classesDir, Arrays.asList(getIncludes()), Arrays.asList(getExcludes())); |
| boolean rebuilt = inputSet.aggregate(jarFile, (output, inputs) -> { | ||
| createArchive(); | ||
| }); |
There was a problem hiding this comment.
output and inputs parameters. createArchive() independently recomputes basedir/finalName/jarFile and writes to its own path. The Output resource provided by the BuildContext (which is the tracked output file) is never used.
If the two path computations ever diverge, the BuildContext would track one file while the actual JAR lives at another. Consider either:
- Refactoring
createArchive()to accept a targetPathparameter, or - Using the
Outputto get the canonical path and passing it through
Also, using (output, inputs) -> with unused params — if this is intentional, a brief comment explaining why would help future readers.
| @@ -47,4 +56,19 @@ void jarTestEnvironment(JarMojo mojo) throws Exception { | |||
|
|
|||
| assertEquals("foo", mojo.getProject().getGroupId()); | |||
There was a problem hiding this comment.
💡 The existing test only verifies mojo wiring (assertNotNull, groupId equality). There's no test for the new incremental execute() path — no coverage for:
aggregate()being called and creating a JAR on first buildmarkSkipExecution()firing when inputs are unchangedforceCreation = truebypassing the incremental check
Given this is the core new behavior, at least one test exercising the BuildContext integration would catch regressions early. (Acknowledged this is experimental — flagging for when it graduates.)
Summary
forceCreationis false and the JAR file already exists, the plugin registers and scans the classes directory viaBuildContext.registerAndProcessInputs()and skips re-packaging if all inputs areUNMODIFIEDmarkSkipExecution()at all skip points (skipIfEmpty, unchanged inputs) so downstream mojos can react accordinglyDetails
This is an experimental branch that depends on:
4.1.0-SNAPSHOT)Changes
AbstractJarMojo.java: Added@Inject BuildContext buildContextfield,hasChangedInputs()method that usesregisterAndProcessInputs()to detect file changes, andattachArtifact()helper. Theexecute()method now checks for changed inputs before creating the JAR.TestJarMojo.java: AddedmarkSkipExecution()in the skip branchJarMojoTest.java: Updated test imports to neworg.apache.maven.testing.pluginpackage, added@Providesmethods forBuildContextandPathMatcherFactorypom.xml: BumpedmavenVersionto4.1.0-SNAPSHOTTest plan
🤖 Generated with Claude Code