Skip to content

Upgrade spotless-maven-plugin to 3.x to support git worktrees #2665

Open

Description

@quando632

Task summary

mvn spotless:check and mvn spotless:apply fail in a checkout created with git worktree add:

Execution default-cli of goal com.diffplug.spotless:spotless-maven-plugin:2.44.5:check failed: Cannot find git repository in any parent directory

In a worktree .git is a file that points to the main repository, and the JGit version bundled with spotless-maven-plugin 2.44.5 cannot follow it. Because of <ratchetFrom> in the root pom.xml, Spotless needs git and so the format tier of the development harness (AGENTS.md, step 4) cannot run in a worktree at all. Worktrees are a common way to work on several issues in parallel, and the contribute skill of #2591 recommends them.

This is a known Spotless issue (diffplug/spotless#1765), fixed in spotless-maven-plugin 3.0.0 by the upgrade to JGit 7.3.

Proposal: upgrade spotless-maven-plugin in the root pom.xml from 2.44.5 to the latest 3.x (3.10.4 at the time of writing).

Things to check in the PR:

  • Breaking changes of 3.0.0: Java 17 is required (fine, IDEasy builds with Java 25), removeWildcardImports was renamed to forbidWildcardImports (not used in our configuration), the git pre-push hook location changed (not used, we have git-hooks/pre-commit).
  • spotless:check on main and on a branch with Java changes gives the same result as before, so that the upgrade does not suddenly flag or reformat existing code.
  • The Check formatting step of .github/workflows/build-pr.yml still passes.
  • Remove the worktree hint from AGENTS.md and the contribute skill that Share agent skills in the repository and close gaps in AGENTS.md #2591 adds.

A quick local check: with the version changed to 3.10.4, mvn spotless:check -pl cli -Dspotless.ratchetFrom=upstream/main succeeds in a worktree, while 2.44.5 fails with the error above.

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementNew feature or requestinternalNothing to be added to CHANGELOG, only internal story

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions