Skip to content

Use ${maven.multiModuleProjectDirectory}/spotless.xml.prefs for robust resolution#188

Closed
khatchad wants to merge 1 commit into
masterfrom
chore/spotless-prefs-multi-module-path
Closed

Use ${maven.multiModuleProjectDirectory}/spotless.xml.prefs for robust resolution#188
khatchad wants to merge 1 commit into
masterfrom
chore/spotless-prefs-multi-module-path

Conversation

@khatchad
Copy link
Copy Markdown
Member

Problem

The XML format block in pom.xml references the Spotless prefs file with a relative path:

```xml

XML

./spotless.xml.prefs


```

Relative paths resolve against Maven's current working directory at invocation time. When Maven is run from the multi-module root (the typical case), this works. But it can fail when run from elsewhere — a submodule's basedir, an IDE's per-module test run, or a nested Maven invocation — because the file isn't at ./spotless.xml.prefs from those contexts.

Fix

Use `${maven.multiModuleProjectDirectory}`, which always points at the directory containing the topmost parent POM regardless of how Maven is invoked:

```xml
${maven.multiModuleProjectDirectory}/spotless.xml.prefs
```

Same pattern downstream consumers like `ponder-lab/Hybridize-Functions-Refactoring` already use for the same file. Cross-repo consistency.

Verification

```
$ mvn spotless:check # from root: BUILD SUCCESS
$ mvn -pl com.ibm.wala.cast.python.ml spotless:check # from root targeting submodule: BUILD SUCCESS
```

Both pass after the change. The submodule-targeted invocation in particular is the case where the relative path was fragile.

…ust resolution

The relative `./spotless.xml.prefs` path resolves correctly when Maven
is invoked from the multi-module root, but can fail when invoked from
elsewhere (e.g., a submodule's `basedir`, an IDE's per-module run, or
nested Maven invocations). Switching to the
`${maven.multiModuleProjectDirectory}` property — which always points
at the directory containing the parent `pom.xml` — makes resolution
robust regardless of invocation context.

Matches the pattern downstream consumers like
`ponder-lab/Hybridize-Functions-Refactoring` already use for the same
file. Verified `mvn spotless:check` and
`mvn -pl com.ibm.wala.cast.python.ml spotless:check` both succeed
after the change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 29, 2026 13:51
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Spotless XML formatter configuration to resolve spotless.xml.prefs via Maven’s multi-module root directory, making formatting checks more reliable across different Maven invocation contexts (root vs submodule, IDE runs, nested builds).

Changes:

  • Replace relative Spotless prefs path (./spotless.xml.prefs) with ${maven.multiModuleProjectDirectory}/spotless.xml.prefs for stable resolution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pom.xml
<type>XML</type>
<files>
<file>./spotless.xml.prefs</file>
<file>${maven.multiModuleProjectDirectory}/spotless.xml.prefs</file>
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${maven.multiModuleProjectDirectory} is only available in newer Maven versions (introduced in Maven 3.3.1). If someone runs this build with an older Maven, interpolation will fail and Spotless config parsing can break. Consider adding a Maven Enforcer rule (or documenting the minimum supported Maven version) so failures are explicit and easier to diagnose.

Copilot uses AI. Check for mistakes.
@khatchad khatchad enabled auto-merge April 29, 2026 13:54
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.29%. Comparing base (eeb9527) to head (276cfbe).

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #188   +/-   ##
=========================================
  Coverage     68.29%   68.29%           
  Complexity     2069     2069           
=========================================
  Files           196      196           
  Lines         17133    17133           
  Branches       2839     2839           
=========================================
  Hits          11701    11701           
  Misses         4320     4320           
  Partials       1112     1112           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@khatchad khatchad closed this Apr 29, 2026
auto-merge was automatically disabled April 29, 2026 13:59

Pull request was closed

@khatchad khatchad deleted the chore/spotless-prefs-multi-module-path branch April 29, 2026 13:59
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.

2 participants