Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dphart opened this issue Apr 21, 2020 · 4 comments
Labels

Comments

@dphart
Copy link

dphart commented Apr 21, 2020

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()
    }
}
@nedtwigg
Copy link
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?

@dphart
Copy link
Author

dphart commented Apr 22, 2020

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.

@nedtwigg
Copy link
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.

@nedtwigg
Copy link
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.

@nedtwigg nedtwigg mentioned this issue May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants