Skip to content

fix: correct spotlessApply path in composite-build violation message - #3007

Merged
nedtwigg merged 3 commits into
diffplug:mainfrom
arimu1:fix/2421-composite-spotlessApply-path
Aug 15, 2026
Merged

fix: correct spotlessApply path in composite-build violation message#3007
nedtwigg merged 3 commits into
diffplug:mainfrom
arimu1:fix/2421-composite-spotlessApply-path

Conversation

@arimu1

@arimu1 arimu1 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #2421.

When Spotless is applied inside an included build of a Gradle composite, spotlessCheck suggested a bare spotlessApply (historically :spotlessApply from project.path alone). Task name selectors do not match tasks in included builds, so the suggested command does not fix the violations.

For example:

my-composite/
├── settings.gradle   # includeBuild('my-utils')
└── my-utils/
    ├── settings.gradle
    └── build.gradle  # applies Spotless

A violation in my-utils is fixed by ./gradlew :my-utils:spotlessApply, not ./gradlew spotlessApply or ./gradlew :spotlessApply.

Fix

  • In the main/root build, keep suggesting bare spotlessApply so one command still fixes every multi-project violation (#2592).
  • In an included build (gradle.parent != null), suggest the build-tree task path, e.g. :my-utils:spotlessApply or :my-utils:lib:spotlessApply.
  • Prefer Project.getBuildTreePath() (Gradle 8.10+); fall back to reconstructing the path from Gradle.getIncludedBuilds() on older supported versions.

Changes

Testing

./gradlew :plugin-gradle:test \
  --tests com.diffplug.gradle.spotless.CompositeBuildRunToFixMessageTest \
  --tests com.diffplug.gradle.spotless.DiffMessageFormatterTest

10/10 passed (JDK 17).

arimu1 and others added 3 commits August 1, 2026 11:12
In included/composite builds, bare spotlessApply does not select tasks
from the included build. Use the build-tree path (e.g. :my-utils:spotlessApply)
in the spotlessCheck run-to-fix message. Standalone multi-project builds
still suggest bare spotlessApply (diffplug#2592).

Fixes diffplug#2421
…otlessApply-path

# Conflicts:
#	plugin-gradle/CHANGES.md
Gradle.getParent() is @nullable, and the loop called it twice — once in
the while condition and again into the local. SpotBugs treats the second
call as independent of the first, so the local was possibly-null where it
was dereferenced. Call it once per iteration into a local the loop
condition guards.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@nedtwigg
nedtwigg enabled auto-merge August 15, 2026 23:15
@nedtwigg
nedtwigg merged commit 3664de3 into diffplug:main Aug 15, 2026
20 checks passed
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.

Logged message to fix formatting violations is incorrect when applied to a composite build

2 participants