Spotless: Bug: Directory 'build/spotless/spotlessKotlin' specified for property 'spotlessOutDirectory' does not exist

Created on 20 Nov 2020  路  4Comments  路  Source: diffplug/spotless

  • [x] summary of problem
$ ./gradlew check

...

FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':{myModuleName}:spotlessKotlinCheck' (type 'SpotlessCheck').
> Directory '{pathToProject}/{myModuleName}/build/spotless/spotlessKotlin' specified for property 'spotlessOutDirectory' does not exist.
  • [x] gradle or maven version

Gradle 6.7.1

  • [x] spotless version

Spotless 5.8.2

  • [x] operating system and version

macOS 10.14.6 (18G6042)

  • [x] copy-paste your full Spotless configuration block(s), ~and a link to a public git repo that reproduces the problem if possible~
spotless {
    format 'misc', {
        target '**/*.gradle', '**/*.properties', '**/*.md', '**/.gitignore', '**/*.yml'
        trimTrailingWhitespace()
        indentWithSpaces()
        endWithNewline()
    }
    kotlin {
        ktlint()
    }
}
  • [x] copy-paste the full content of any console errors emitted by gradlew spotless[Apply/Check] --stacktrace

See summary above.

bug-unconfirmed

All 4 comments

The problem is solved if I specify Kotlin targets:

diff --git a/build.gradle b/build.gradle
index 80187b5..442ebe2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -122,6 +122,7 @@ subprojects {
             endWithNewline()
         }
         kotlin {
+            target '**/src/**/*.kt', '**/src/**/*.kts'
             ktlint()
         }
     }

Now the problem has solved itself. 馃槙
I was running 'CtrlCtrl gradle check Enter' from Android Studio. That lead to the problem above. When running ./gradlew check from CLI there was no issue. (???) Then, when running it from AS again, the issue was gone. (???) Even when doing a Gradle clean (which removes the missing directory) before check doesn't reproduce the issue.

I'm confused.

Interesting. Each format has three tasks. In your case, there is spotlessKotlin, spotlessKotlinCheck, and spotlessKotlinApply.

The job of spotlessKotlin is to check the formatting of target, and write the correctly formatted result into build/spotless/spotlessKotlin. The spotlessKotlin task has up-to-date checking, buildcache, etc.

The other two tasks, check and apply, just look at the build/spotless/spotlessKotlin directory, but they do not support up-to-date, buildcache, etc. Well, they kind of do, but only in that spotlessKotlin does all of the actual computation and work, and then check and apply just interpret that result.

For a clean build, the directory needed by spotlessKotlinCheck and spotlessKotlinApply does not exist, because it is created by spotlessKotlin.

https://github.com/diffplug/spotless/blob/d9474fbffb03cfa1f54c55b8c3beebe81cd7611a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java#L140-L143

https://github.com/diffplug/spotless/blob/d9474fbffb03cfa1f54c55b8c3beebe81cd7611a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java#L46-L50

https://github.com/diffplug/spotless/blob/d9474fbffb03cfa1f54c55b8c3beebe81cd7611a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessApply.java#L43-L47

Since check and apply don't have any outputs (as far as Gradle is concerned), I wonder if we should not declare any inputs either... @bigdaz any thoughts on this?

Related to this, we should enable support for @IgnoreEmptyDirectories when used on Gradle 6.8+

Was this page helpful?
0 / 5 - 0 ratings