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

ktfmt-gradle needs at least Gradle 7.2 #110

Closed
arturbosch opened this issue Dec 16, 2022 · 7 comments · Fixed by #111
Closed

ktfmt-gradle needs at least Gradle 7.2 #110

arturbosch opened this issue Dec 16, 2022 · 7 comments · Fixed by #111

Comments

@arturbosch
Copy link

arturbosch commented Dec 16, 2022

🐛 Describe the bug

Readme states that Gradle 6.8+ is supported.

⚠️ Current behavior

String.titlecase was introduced in Kotlin 1.5 which is shipped with Gradle starting from 7.2.
We are running Gradle 6.9.2 and can't upgrade due to Gradle 7.0 removed the feature to switch Java compilers.

✅ Expected behavior

There are two options:

  1. Update Readme to only support Gradle 7.2+
  2. fix titlecase usage (and maybe further 1.5 features ? maybe appendLn) to be Kotlin 1.4 compatible.

💣 Steps to reproduce

Run any project with Gradle 6.9.2 and the ktfmt plugin installed.

📷 Screenshots

Screenshot from 2022-12-16 14-30-46

📱 Tech info

  • Device: Dell Xps 15
  • OS: ubuntu 22.10
@cortinico
Copy link
Owner

Ooops that sucks. Yup I think addressing the titlecase usage would be preferred and setting languageLevel to 1.4 should suffice. Are you up for a PR @arturbosch ? :)

@arturbosch
Copy link
Author

Ooops that sucks. Yup I think addressing the titlecase usage would be preferred and setting languageLevel to 1.4 should suffice. Are you up for a PR @arturbosch ? :)

Well maybe, I'm not sure how to fix this as titlecase uses a Locale and converts a Char to a possible multi-char string.
There is no direct replacement in the jdk for it :/. Character.toTitleCase(char) does a bit less under the hood as it seems.
So this only applies to some wierd unicode task names ... is it important ?

@cortinico
Copy link
Owner

I took a stab at this here:

I've tested this on a Gradle project with 6.9 and I managed to make it work.
The problem you'll face @arturbosch, is that ktfmt-gradle is adding a dep. constraint on "org.jetbrains.kotlin:kotlin-compiler-embeddable:..." on version 1.7.22.

The reason why this is needed is #93 and the linked YouTrack issue.
So even if you're on Gradle 6.9, you'll pull in kotlin-compiler-embeddable for 1.7

The workaround is for you to pin the kotlin-compiler-embeddable in your build as:

buildscript {
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.4.32") {
            version {
                strictly("1.4.32")
            }
        }
    }
}

Removing the dep. constraint on kotlin-compiler-embeddable will make it unusable for users on Kotlin 1.7.

@arturbosch
Copy link
Author

I took a stab at this here:

I've tested this on a Gradle project with 6.9 and I managed to make it work. The problem you'll face @arturbosch, is that ktfmt-gradle is adding a dep. constraint on "org.jetbrains.kotlin:kotlin-compiler-embeddable:..." on version 1.7.22.

The reason why this is needed is #93 and the linked YouTrack issue. So even if you're on Gradle 6.9, you'll pull in kotlin-compiler-embeddable for 1.7

The workaround is for you to pin the kotlin-compiler-embeddable in your build as:

buildscript {
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.4.32") {
            version {
                strictly("1.4.32")
            }
        }
    }
}

Removing the dep. constraint on kotlin-compiler-embeddable will make it unusable for users on Kotlin 1.7.

Thanks! Will I need the workaround if we already use Kotlin 1.7.X Gradle plugin?

@cortinico
Copy link
Owner

if we already use Kotlin 1.7.X Gradle plugin?

Not really. But then I don't fully understand what's your setup.
What's your Gradle version and the KGP version you're on? Are there any other Gradle Plugins that are pulling in kotlin-compiler-embeddable? (A gradle scan might help to understand).

@arturbosch
Copy link
Author

if we already use Kotlin 1.7.X Gradle plugin?

Not really. But then I don't fully understand what's your setup. What's your Gradle version and the KGP version you're on? Are there any other Gradle Plugins that are pulling in kotlin-compiler-embeddable? (A gradle scan might help to understand).

Oh, my misunderstanding. You wrote contraint for the buildscript block.
We use Gradle 6.9.X which ships with Kotlin-Embeddable 1.4.20 and KGP 1.7.1.
Also detekt 1.22.0 and IntelliJ-Gradle-Plugin 1.10.2 which do not ship the Kotlin compiler transitively.

@cortinico
Copy link
Owner

Oh, my misunderstanding. You wrote contraint for the buildscript block. We use Gradle 6.9.X which ships with Kotlin-Embeddable 1.4.20 and KGP 1.7.1. Also detekt 1.22.0 and IntelliJ-Gradle-Plugin 1.10.2 which do not ship the Kotlin compiler transitively.

Thanks for sharing. I've tested with your setup and the fix works correctly 👍

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

Successfully merging a pull request may close this issue.

2 participants