question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spotless is breaking configuration avoidance for other tasks

See original GitHub issue

By default, spotless adds the spotlessCheck task as a dependency of the check task. The check task might not exist yet when the spotless task is applied. To allow Spotless to be applied before or after the JavaBasePlugin, we get the check task like this:

https://github.com/diffplug/spotless/blob/def65a1541abd8841d4754278ab45d87537a48f0/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java#L114-L116

The problem is that this appears to trigger task configuration for every task in the project.

This is different than Spotless using configuration avoidance itself, this is about Spotless breaking configuration avoidance for other plugins. There has been a long discussion about moving Spotless itself to use configuration avoidance. The end result of that discussion is this unmerged code, which I believe (perhaps mistakenly) will trigger the exact same issue:

https://github.com/carbotaniuman/spotless/blob/93ae599bcbc71848bbd8d48de2ab9532d3fb420b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskSetupConfigAvoidance.java#L92-L96

Configuration avoidance is a performance enhancement. If you adopt the APIs, but don’t test that the build has actually gotten faster / configuration has actually been avoided, then you may or may not be getting any advantage from the work.

If you want to fix this issue, it is easy to experiment right in your buildscript. For example:

spotless {
  enforceCheck = false
}
afterEvaluate {
  tasks.check.dependsOn(tasks.spotlessCheck)
}

This will produce the exact same behavior as enforceCheck = true, but it might fix the configuration avoidance problem. To get a fix merged, it will need to meet the following criteria:

  • The fix has been tested and confirmed to actually fix the “eagerly configure other tasks” problem
  • Whether the check task is created before or after spotless is applied, Spotless will integrate with it
  • (maybe) If no check task exists, Spotless should create one
    • Spotless does not do this right now
    • It probably should though - if you have a folder (e.g. manual) which just has markdown and the only plugin is Spotless, then gradlew check ought to check the formatting of that folder.

Strikethrough is edit by Ned Twigg 9/29: I was wrong about this, Spotless already applies BasePlugin, which creates check. I was confused because the String constant for check is JavaBasePlugin.CHECK_TASK_NAME.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
carbotaniumancommented, Nov 9, 2019

@nedtwigg I just got back from some other work to focus on the project that inspired this, and I noticed that task configuration avoidance was working properly. Thanks for merging this, I can now rest assured knowing I only have 1 task configured when I run the help command.

For what it’s worth, my unmerged code works correctly, because configureEach() is lazy. 😛

1reaction
JLLeitschuhcommented, Sep 30, 2019

@esword That’s quite an impressive performance improvement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Task Configuration Avoidance - Gradle User Manual
To avoid creating and configuring tasks, we say that a task is "registered" but not created.
Read more >
Gradle: Spotless task not firing when needed - Stack Overflow
When I run "gradlew build", I expect Spotless to a) format my code automatically using the above format; b) do a check (ie...
Read more >
Vol. 81 Tuesday, No. 65 April 5, 2016 Pages 19467–19856 - GovInfo
Butterfly, San Bernardino Flying Squirrel, Spotless ... action, but other tasks for post-trimming ... a configuration where one or both LH and RH....
Read more >
Kotlin Gradle Plugin: Use new Gradle API for Lazy tasks
also waiting for fix. this is showstopper for using task configuration avoidance for me. other way is to use java but I don't...
Read more >
roborock s5 max auto empty
Part 1: How to Setup & Configure Roborock S7 with H…. ... S7 MaxV Plus Robotic Vacuum Cleaner and Sonic Mop Auto-Empty Dock...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found