Skip to content

experiment: leverage BuildContext API for incremental JAR creation - #566

Draft
gnodet wants to merge 2 commits into
masterfrom
experiment/maven4-build-context
Draft

experiment: leverage BuildContext API for incremental JAR creation#566
gnodet wants to merge 2 commits into
masterfrom
experiment/maven4-build-context

Conversation

@gnodet

@gnodet gnodet commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • 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 registers and scans the classes directory via BuildContext.registerAndProcessInputs() and skips re-packaging if all inputs are UNMODIFIED
  • Signals markSkipExecution() at all skip points (skipIfEmpty, unchanged inputs) so downstream mojos can react accordingly

Details

This is an experimental branch that depends on:

Changes

  • AbstractJarMojo.java: Added @Inject BuildContext buildContext field, hasChangedInputs() method that uses registerAndProcessInputs() to detect file changes, and attachArtifact() helper. The execute() method now checks for changed inputs before creating the JAR.
  • TestJarMojo.java: Added markSkipExecution() in the skip branch
  • JarMojoTest.java: Updated test imports to new org.apache.maven.testing.plugin package, added @Provides methods for BuildContext and PathMatcherFactory
  • pom.xml: Bumped mavenVersion to 4.1.0-SNAPSHOT

Test plan

  • All existing tests pass (1/1)
  • Integration testing with a multi-module project to verify JAR skipping

🤖 Generated with Claude Code

gnodet and others added 2 commits July 29, 2026 16:17
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant