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

Support Kotlin 1.4 with ktlint 0.38.0 #383

Closed
bjoernmayer opened this issue Aug 23, 2020 · 7 comments · Fixed by #393
Closed

Support Kotlin 1.4 with ktlint 0.38.0 #383

bjoernmayer opened this issue Aug 23, 2020 · 7 comments · Fixed by #393
Assignees
Labels

Comments

@bjoernmayer
Copy link

Version 0.38.0 of ktlint brings support for Kotlin 1.4.

Do you plan to release a new version ktlint-gradle supporting the new ktlint version?

@Tapchicoma
Copy link
Collaborator

you could set ktlint version via extension property:

val version: Property<String> = objectFactory.property { set("0.37.2") }

0.38.0 should work as well.

@bjoernmayer
Copy link
Author

bjoernmayer commented Aug 23, 2020

Yep.
Doing that already:

ktlint {
    this.version.set("0.38.0-alpha01")
}

A released version of ktlint-gradle supporting 1.4 would still be nice though

@zarebski-m
Copy link

The plugin doesn't work with Kotlin 1.4.0 for me – I've tried versions 9.2.1 and 9.3.0. I've set ktlint version to 0.38.1:

ktlint {
    version.set("0.38.1")
    verbose.set(true)
    disabledRules.set(setOf("import-ordering", "no-wildcard-imports"))
}

I get the folowing error:

> 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)

Is it possible that not all com.pinterest.ktlint dependencies are set to the selected version?

See also: pinterest/ktlint#876. I honestly don't know where is the problem: in ktlint or ktlint-gradle

@Tapchicoma Tapchicoma added bug and removed question labels Sep 3, 2020
@Tapchicoma
Copy link
Collaborator

Found the issue:

  • ktlint-gradle adds ktlint configuration that is used to pull ktlint itself
  • when project are still using kotlin 1.3.+ this is leaked into ktlint configuration leading to usage of incompatible kotlin version.

I am looking how to fix it, workaround would be either:

  • use ktlint version < 0.38.+
  • update your project to use Kotlin 1.4.+

@Tapchicoma Tapchicoma self-assigned this Sep 3, 2020
@Tapchicoma
Copy link
Collaborator

Actually after further investigation in affected project I found out following gradle configuration that forcing kotlin version for all configurations:

configurations.all {
    resolutionStrategy {
        eachDependency {
            // Force Kotlin to our version
            if (requested.group == "org.jetbrains.kotlin") {
                useVersion("1.3.72")
            }
        }
    }
}

This enforces kotlin version also for ktlint configuration that is created by plugin to dynamically add ktlint and leads to errors running ktlint 0.38+ versions.

To avoid it you should exclude ktlint* configurations from kotlin version enforcement.

@alex-t0
Copy link

alex-t0 commented Sep 4, 2020

Hi @Tapchicoma!

Can you provide small example how to exclude ktlint* configurations from kotlin version enforcement?

@Tapchicoma
Copy link
Collaborator

@alex-t0 something like this should work:

configurations.all {
    if(!name.startsWith("ktlint")) {
        resolutionStrategy {
            eachDependency {
                // Force Kotlin to our version
                if (requested.group == "org.jetbrains.kotlin") {
                    useVersion("1.3.72")
                }
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants