Skip to content

Spotless gradle is super slow and doesn't appear to respect the -PspotlessFiles flag #557

Closed

Description

@dphart

Using
id "com.diffplug.gradle.spotless" version "3.28.1"
I'm seeing a spotlessApply, which it thinks is cached, taking over a minute.

For this build I also ran it with the -PspotlessFiles=build.gradle flag, which I would think should cut down on the time to run but it's still taking over a minute. The only thing that changed was a single white space.

Am I missing something? Is this a typical run time? The project isn't massive.
https://scans.gradle.com/s/pcwl4s6sc7oio

spotless {
    enforceCheck = true
    java {
        target '**/*.java'
        targetExclude '**/.gradle/', '**/build/'
        removeUnusedImports()
        trimTrailingWhitespace()
        indentWithSpaces()
        endWithNewline()
        googleJavaFormat().aosp()
    }
    kotlin {
        target '**/*.kt'
        targetExclude '**/.gradle/', '**/build/'
        trimTrailingWhitespace()
        indentWithSpaces()
        endWithNewline()
        ktlint('0.36.0').userData(['disabled_rules': 'no-wildcard-imports'])
    }
    format 'xml', {
        target '**/*.xml'
        targetExclude '**/.idea/', '**/.gradle/', '**/build/'
        indentWithSpaces()
        trimTrailingWhitespace()
        endWithNewline()
    }
    format 'misc', {
        target '**/*.gradle', '**/*.md', '**/.gitignore'
        targetExclude '**/.gradle/', '**/build/'
        indentWithSpaces()
        trimTrailingWhitespace()
        endWithNewline()
    }
}

Activity

  1. nedtwigg commented on Apr 22, 2020

    @nedtwigg
    Member

    Your build time is long because your targets are all **/*.xx. It would be a lot faster if it were instead src/xx/**/*.xx or *.xx. The time is being consumed in giant directory traversals looking for .xx files, then again in another giant traversal to look for .yy files, and so on.

    With -PspotlessFiles, you're not specifying the target, you're just filtering it. So it still has to resolve every directory traversal, and then see if any of those files String#matches(String) the regex that you've passed (might want to escape the . by the way).

    What are you using -PspotlessFiles for? Would #511 work for you?

  2. dphart commented on Apr 22, 2020

    @dphart
    Author

    So interesting find, Changing the way I bring in the plugin, it's now running in under 10 seconds. Using the older classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.28.1 has helped.
    I don't know why changing the way the dependency is imoported drastically changes run times.

    #511 would roughly work, it looks like that's an open issue. They're trying to more or less achieve the same thing I am, and that Spotless only runs on files that have changed since the last commit.

  3. nedtwigg commented on Apr 22, 2020

    @nedtwigg
    Member

    If you change back to the “slow” way, is it still slow? Or are they the same speed now? There’s a lot of caching going on, I wouldn’t expect any speed difference between the two approaches.

  4. nedtwigg commented on Apr 28, 2020

    @nedtwigg
    Member

    Happy to reopen if you find more info, but I suspect that implementing #511 is going to be the final solution to this, -PspotlessFiles has proven to be tricky for people to use.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions