After upgrade ktlint to 38.1 (from 37.2) we get the following error:
> Task :ktlintFormat
Exception in thread "main" java.lang.NoSuchFieldError: FUN_KEYWORD
at com.pinterest.ktlint.core.ast.ElementType.<clinit>(ElementType.kt:154)
at com.pinterest.ktlint.ruleset.experimental.SpacingAroundAngleBracketsRule.<clinit>(SpacingAroundAngleBracketsRule.kt:94)
at com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider.get(ExperimentalRuleSetProvider.kt:18)
at com.pinterest.ktlint.KtlintCommandLine.loadRulesets(Main.kt:550)
at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:222)
at com.pinterest.ktlint.Main.main(Main.kt:62)
thanks
Chen
Have you also updated kotlin to 1.4?
I also get this error with ktlint 0.38.1 and Kotlin 1.4.0. No problem with Kotlin 1.3.72.
> Task :module:ktlintKotlinScriptCheck FAILED
Exception in thread "main" java.lang.NoSuchFieldError: FUN_KEYWORD
at com.pinterest.ktlint.core.ast.ElementType.<clinit>(ElementType.kt:154)
at com.pinterest.ktlint.ruleset.experimental.SpacingAroundAngleBracketsRule.<clinit>(SpacingAroundAngleBracketsRule.kt:94)
at com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider.get(ExperimentalRuleSetProvider.kt:18)
at com.pinterest.ktlint.KtlintCommandLine.loadRulesets(Main.kt:550)
at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:222)
at com.pinterest.ktlint.Main.main(Main.kt:62)
Yeah, same here. I upgraded Kotlin to 1.4.0 and I cannot run the klint check anymore using Gradle.
Do you have .gradle.kts files in your project?
Could you attach here file that failing with above error?
I don't know if this is helpful, but ktlint fails on the following file (which is part of a bigger multi-module project):
plugins {
application
id("org.springframework.boot")
id("com.gorylenko.gradle-git-properties")
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.cloud:spring-cloud-starter-stream-rabbit")
implementation("org.springframework.cloud:spring-cloud-starter-vault-config")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("io.sentry:sentry-logback")
implementation("mysql:mysql-connector-java")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.cloud:spring-cloud-stream-test-support")
testImplementation("org.spockframework:spock-core")
testImplementation("org.spockframework:spock-spring")
testImplementation("com.h2database:h2")
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
}
springBoot {
buildInfo()
}
application {
mainClassName = "XXX" // redacted
}
tasks {
jar { enabled = true }
bootJar { archiveClassifier.set("app") }
processResources {
filesMatching(listOf("sentry.properties")) {
expand(project.properties)
}
}
}
What might be helpful as well is that I'm not using pinterest/ktlint directly, but rather via JLLeitschuh/ktlint-gradle with the following configuration:
ktlint {
version.set("0.38.1")
verbose.set(true)
disabledRules.set(setOf("import-ordering", "no-wildcard-imports"))
}
I could reproduce it as well on my work project. Most probably related to ktlint-gradle plugin and not KtLint itself.
Please check this comment in ktlint-gradle: https://github.com/JLLeitschuh/ktlint-gradle/issues/383#issuecomment-686755121
Most probably this is your case and why it is not working.