ktlint-gradle icon indicating copy to clipboard operation
ktlint-gradle copied to clipboard

Error with kotlin 2.0.1

Open nckdistributable opened this issue 1 year ago • 7 comments

Hi, I'm getting an error when executing the ktlintCheck task. The error is:

Execution failed for task ':runKtlintCheckOverKotlinScripts'.
> A failure occurred while executing org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction
   > Class org.jetbrains.kotlin.lexer.KtTokens does not have member field 'org.jetbrains.kotlin.lexer.KtModifierKeywordToken HEADER_KEYWORD'

I found that this keyword was removed in the most recent versions of the Kotlin compiler. Is the current version of ktlint aware of this?

Thanks!

nckdistributable avatar Nov 29 '24 13:11 nckdistributable

This might be about Kotlin 2.1.0, not 2.0.1.

cbartolome avatar Dec 02 '24 20:12 cbartolome

This error has been fixed in ktlint lib version 1.4.0, but this plugin is using an slightly older version of the lib.

In build.gradle.kts we can configure the plugin to use the most recent version of ktlint.

ktlint {
    version.set("1.4.1")
}

That should fix the error for now.

gmmoreira avatar Dec 03 '24 20:12 gmmoreira

A PR updating the default Ktlint version would be appreciated and accepted with a simple unit test and a CHANGELOG entry

JLLeitschuh avatar Dec 08 '24 14:12 JLLeitschuh

I hope this PR is what you were looking for: #818

CPColin avatar Dec 09 '24 18:12 CPColin

setting to ktlint version to 1.5 leads to failing on a lot of validations, did anyone experienced the same?

dumitrurogojinaru avatar Apr 25 '25 13:04 dumitrurogojinaru

setting to ktlint version to 1.5 leads to failing on a lot of validations, did anyone experienced the same?

if you were p reviously on a pre-1.0 version of ktlint, then yeah a lot of things changed in ktlint. This is a big reason why we have been dragging our feet on updating the default version in ktlint-gradle. I recommend looking at the ktlint github for advise on the changes to the ktlint rules

wakingrufus avatar Apr 25 '25 14:04 wakingrufus

thank a lot, already found some info and it seems that this setup solved quite a lot, as I understood that prior version where same as in IntelliJ. Additionally will add separately what's failing. Thanks a lot for quick answer!

additionalEditorconfig = [ 'ktlint_code_style': 'intellij_idea' ]

dumitrurogojinaru avatar Apr 25 '25 14:04 dumitrurogojinaru

I believe this issue can be closed with https://github.com/JLLeitschuh/ktlint-gradle/releases/tag/v13.0.0 that sets the default ktlint version to 1.5

gustavo-hsu-wu avatar Jul 14 '25 08:07 gustavo-hsu-wu

This is still valid issue for me with v13.0.0 and Kotlin v2.2.0

mkubele avatar Jul 25 '25 15:07 mkubele

We did indeed upgrade the default ktlint version in 13.0. We will continue to update this each time we do a major version bump

wakingrufus avatar Aug 21 '25 13:08 wakingrufus