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.

Consider migrating Spotless Gradle plugin to use Task Configuration Avoidance

See original GitHub issue

I’m in the middle of migrating my personal project jupiter-collection-testers to use a new feature introduced in Gradle 4.9 called Task Configuration Avoidance, over at this feature branch. However, I am currently stuck on the Spotless Gradle plugin, because even if I don’t run gradlew spotless[Check|Apply], the plugin seems to directly depend on and thus eagerly configure (create) a number of tasks which spotless[Check|Apply] needs but other tasks like help don’t need.

The reason that I believe Spotless is eagerly configuring these tasks, whichever ones they are, is because when I comment out these lines, the command gradlew help -Dorg.gradle.internal.tasks.stats produces the following relatively small output,

1 actionable task: 1 executed
Task counts: Old API 1, New API 58, total 59
Task counts: created 3, avoided 56, %-lazy 95

Task types that were created with the old API
class com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask 1

Task types that were registered with the new API but were created anyways
class org.gradle.configuration.Help 1
class org.gradle.api.tasks.bundling.Jar 1

as opposed to the following larger output,

1 actionable task: 1 executed
Task counts: Old API 12, New API 74, total 86
Task counts: created 75, avoided 11, %-lazy 13

Task types that were created with the old API
class org.gradle.api.DefaultTask 8
class com.diffplug.gradle.spotless.SpotlessTask 3
class com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask 1

Task types that were registered with the new API but were created anyways
class org.gradle.api.tasks.compile.JavaCompile 23
class org.gradle.api.DefaultTask 13
class org.gradle.api.tasks.Delete 9
class org.gradle.language.jvm.tasks.ProcessResources 3
class org.gradle.api.plugins.quality.Pmd 3
class org.gradle.api.tasks.testing.Test 1
class org.gradle.kotlin.dsl.accessors.tasks.PrintAccessors 1
class org.gradle.api.tasks.javadoc.Javadoc 1
class org.gradle.plugins.ide.eclipse.GenerateEclipseJdt 1
class org.gradle.plugins.ide.idea.GenerateIdeaModule 1
class org.gradle.plugins.ide.eclipse.GenerateEclipseClasspath 1
class org.gradle.plugins.ide.eclipse.GenerateEclipseProject 1
class org.gradle.kotlin.dsl.accessors.tasks.UpdateProjectSchema 1
class org.gradle.configuration.Help 1
class org.gradle.plugins.ide.idea.GenerateIdeaWorkspace 1
class org.gradle.api.tasks.bundling.Jar 1
class org.gradle.plugins.ide.idea.GenerateIdeaProject 1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:22 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
nedtwiggcommented, Oct 7, 2019

For the benefit of issue subs, this has been released (partially, see #444 for details) in 3.25.0.

1reaction
dmoidlcommented, Aug 26, 2019

Hi @nedtwigg,

since this issue already exists, I’m not opening a new one, but I still think that Spotless plugin not playing well with Gradle’s configuration avoidance is an issue.

I recently stumbled upon this when I tried to use configuration avoidance to simplify our build script and realized it’s not working. After some debugging I came to the very same conclusion as OP did - Spotless plugin actually causes some tasks to get configured, while these tasks would not get configured in its absence. This doesn’t seem right to me.

You see, I don’t really care about how Spotless plugin is coded and whether or not it uses the configuration avoidance internally for it’s own stuff, but I do think that it should not mess with other tasks which aren’t associated with spotless in any way. Not only because it’s not necessary, but because some people (such as myself) might actually want to benefit from configuration avoidance in some way and Spotless plugin breaks this.

I didn’t do any in-depth analysis, but just a quick check of the source code, yet I found this part of the code to be the cause of the problem. Obviously, iterating over these tasks makes Gradle configure them even though it normally wouldn’t (using Gradle 5.6, btw.). Knowing that, I came up with a workaround: setting enforceCheck to false on the Spotless extension and manually setting spotlessCheck task as a dependency of Gradle’s built-in check task does the trick.

Since I haven’t yet had the need to study Gradle’s Plugin API, I can’t tell how difficult it would be to fix this. Nevertheless, I think it should be fixed and wanted to bring this up as IMHO, this is not just a performance issue, but an issue in general.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Task Configuration Avoidance - Gradle User Manual
This chapter provides an introduction to "configuration avoidance" when dealing with tasks and explains some guidelines for migrating your build to use the ......
Read more >
Kotlin Gradle Plugin: Use new Gradle API for Lazy tasks
This API allows minimizing amount of tasks created on each build or task invocation. It's especially important for big multimodule projects because each...
Read more >
diffplug/spotless - Gitter
First solution: just run ./gradlew spotlessApply build or ./gradlew spotlessApply check instead of just ./gradlew [build|check] . Spotless is reasonably fast, ...
Read more >
there are 8 wrapper classes in java - El Primer Grande
A-143, 9th Floor, Sovereign Corporate Tower, We use cookies to ensure you ... There are cases where Gradle tasks will generate Java classes....
Read more >
Custom pluggable types for ... - The Checker Framework Manual
If your project manages dependencies using a tool such as Gradle or Maven, ... As an example, consider the Nullness Checker.
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