hey all, I have this task for detekt: ```apply p...
# detekt
m
hey all, I have this task for detekt:
Copy code
apply plugin: 'io.gitlab.arturbosch.detekt'

def projectSource = file(projectDir)
def configFile = files("${rootProject.projectDir}/config/detekt/detekt.yml")
def baselineFile = file("${rootProject.projectDir}/config/detekt/baseline.xml")
def kotlinFiles = "**/*.kt"
def resourceFiles = "**/resources/**"
def buildFiles = "**/build/**"

tasks.register("detektAll", Detekt) {
    description = "Custom DETEKT build for all modules"
    parallel = true
    ignoreFailures = false
    autoCorrect = false
    buildUponDefaultConfig = true
    setSource(projectSource)
    baseline.set(baselineFile)
    config.setFrom(configFile)
    include(kotlinFiles)
    exclude(resourceFiles, buildFiles)
    reports {
        html.required.set(true)
        xml.required.set(false)
        txt.required.set(false)
    }
}
And I have a dependency on the detekt plugin formatting
detektPlugins(libs.detekt.formatting)
. However when I run the task with
./gradlew detektAll --auto-correct
or
./gradlew detektAll -PdetektAutoFix=true
I'm getting errors such as:
Copy code
./gradlew detektAll --auto-correct
Configuration on demand is an incubating feature.
> Task :detektAll FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':detektAll'.
> java.lang.IllegalStateException:        Analyzing /Users/myuser/Developer/myandroidapp/app/src/test/java/package/uk/presentation/screens/TagsInputProcessorTest.kt led to an exception.
         Location: java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
         The original exception message was: java.lang.IllegalArgumentException: Stack should be empty:
  IndentContext(fromASTNode=Element(kotlin.FILE), toASTNode=PsiWhiteSpace, nodeIndent=, firstChildIndent=, childIndent=, lastChildIndent=, activated=true)
  IndentContext(fromASTNode=Element(CLASS), toASTNode=PsiElement(RBRACE), nodeIndent=, firstChildIndent=, childIndent=, lastChildIndent=, activated=false)
  IndentContext(fromASTNode=Element(CLASS_BODY), toASTNode=PsiElement(RBRACE), nodeIndent=, firstChildIndent=    , childIndent=    , lastChildIndent=, activated=false)
  IndentContext(fromASTNode=PsiElement(LBRACE), toASTNode=PsiElement(RBRACE), nodeIndent=, firstChildIndent=, childIndent=    , lastChildIndent=, activated=true)
  IndentContext(fromASTNode=BLOCK, toASTNode=PsiElement(RBRACE), nodeIndent=    , firstChildIndent=    , childIndent=    , lastChildIndent=    , activated=false)
  IndentContext(fromASTNode=Element(FUN), toASTNode=PsiElement(RPAR), nodeIndent=    , firstChildIndent=, childIndent=, lastChildIndent=, activated=true)
  IndentContext(fromASTNode=BLOCK, toASTNode=PsiElement(RBRACE), nodeIndent=    , firstChildIndent=    , childIndent=    , lastChildIndent=    , activated=false)
  IndentContext(fromASTNode=Element(FUN), toASTNode=PsiElement(RPAR), nodeIndent=    , firstChildIndent=, childIndent=, lastChildIndent=, activated=true)
  IndentContext(fromASTNode=BLOCK, toASTNode=PsiElement(RBRACE), nodeIndent=    , firstChildIndent=    , childIndent=    , lastChildIndent=    , activated=false)
  IndentContext(fromASTNode=Element(FUN), toASTNode=PsiElement(RPAR), nodeIndent=    , firstChildIndent=, childIndent=, lastChildIndent=, activated=true)
  IndentContext(fromASTNode=BLOCK, toASTNode=PsiElement(RBRACE), nodeIndent=    , firstChildIndent=    , childIndent=    , lastChildIndent=    , activated=false)
  IndentContext(fromASTNode=Element(FUN), toASTNode=PsiElement(RPAR), nodeIndent=    , firstChildIndent=, childIndent=, lastChildIndent=, activated=true)
         Running detekt '1.23.0' on Java '17.0.6+10' on OS 'Mac OS X'
         If the exception message does not help, please feel free to create an issue on our GitHub page.
t
If you disable parallelization do you still get the error? When I've seen a similar error, I've attributed it to one rule modifying a file as another processes it. Never had a reliable reproduction though, or more than a guess, to open an issue
m
let me check
I just set
org.gradle.parallel=false
and I'm still getting the same
I'm really struggling with detekt and the autoCorrect