Visitar URL original
Update to Kotlin 2.0.0 by 3flex · Pull Request #6640 · detekt/detekt · GitHub
Skip to content

Update to Kotlin 2.0.0 - #6640

Merged
3flex merged 6 commits into
detekt:mainfrom
3flex:kotlin-2
May 22, 2024
Merged

3flex merged 6 commits into
detekt:mainfrom
3flex:kotlin-2

Conversation

@3flex

@3flex 3flex commented Nov 23, 2023 •

Copy link
Copy Markdown
Member

Fixes #6715
Fixes #7458

This is safe to release with alpha/beta dependencies in my opinion. poko 0.16.0-beta01 is based on Kotlin 2.0.0-RC3 which is the same as 2.0.0. kctfork is only used in tests.

@detekt-ci detekt-ci added rules build dependencies Pull requests that update a dependency file compiler-plugin labels Nov 23, 2023
@3flex 3flex changed the title [WIP] Kotlin 2 [WIP] Kotlin 2.0 support Nov 23, 2023
@detekt-ci detekt-ci added the api label Nov 26, 2023
@jarroyoesp

Copy link
Copy Markdown

Hey @3flex after trying the commit 429a178 as you mentioned here #6715 (comment). I've been able to compile your branch and generate the library on my MavenLocal. But when I've run detekt in my project, I am getting the following errors:

> Task :build-conventions:compileKotlin FAILED
e: Pre-release classes were found in dependencies. Remove them from the classpath, recompile with a release compiler or use '-Xskip-prerelease-check' to suppress errors
e: file:///Users/javierarroyo/Projects/Personal/Forlago/build-conventions/build/generated-sources/kotlin-dsl-accessors/kotlin/gradle/kotlin/dsl/accessors/_2fb462c0d2ba107f613d15985247d494/Accessors32ikgp1isdd8mwexzgbe6rirl.kt:65:44 Class 'io.gitlab.arturbosch.detekt.extensions.DetektExtension' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler

Thanks :)

@3flex

3flex commented Dec 20, 2023 •

Copy link
Copy Markdown
Member Author

You probably need to follow steps here: https://docs.gradle.org/8.3/release-notes.html#kotlin_k2 and be sure to use Gradle 8.3 or higher.

Also have a read of https://kotlinlang.org/docs/whatsnew-eap.html#current-k2-compiler-limitations

@3flex
3flex force-pushed the kotlin-2 branch 2 times, most recently from 8652daa to 68f3cc7 Compare December 22, 2023 05:17
@codecov

codecov Bot commented Dec 22, 2023 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 84.36%. Comparing base (e79f038) to head (73c8d7e).
Report is 168 commits behind head on main.

Files Patch % Lines
...lin/io/github/detekt/parser/BindingContextUtils.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6640      +/-   ##
============================================
- Coverage     84.68%   84.36%   -0.33%     
- Complexity     4001     4176     +175     
============================================
  Files           574      574              
  Lines         12011    11913      -98     
  Branches       2476     2458      -18     
============================================
- Hits          10172    10050     -122     
- Misses          598      613      +15     
- Partials       1241     1250       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BraisGabin BraisGabin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@3flex

3flex commented May 22, 2024 •

Copy link
Copy Markdown
Member Author

If this is cherry picked into the 1.x branch, these PRs will also need to be picked:

@nevertooserious

Copy link
Copy Markdown

Kotlin 2.0 has just been released. I see this has been merged - are you planning to publish a release relatively soon? :)

@3flex

3flex commented May 22, 2024

Copy link
Copy Markdown
Member Author

I haven't made releases previously so I can't say, but you can try snapshots until a new one is pushed out.

@TWiStErRob

Copy link
Copy Markdown
Member

@cortinico are you planning a patch with Kotlin 2.0.0 support? (current 1.23.6 works, but I would assume that the K2 improvements propagate to compiler-embedded, so a detekt patch/minor release could benefit from a 2x speed improvement?)

@cortinico

Copy link
Copy Markdown
Member

@cortinico are you planning a patch with Kotlin 2.0.0 support? (current 1.23.6 works, but I would assume that the K2 improvements propagate to compiler-embedded, so a detekt patch/minor release could benefit from a 2x speed improvement?)

I was thinking we can cut a 2.0.0-alpha-01 or so from the main branch to overcome this. Wdyt @TWiStErRob @3flex ?

@TWiStErRob

Copy link
Copy Markdown
Member

It feels like that might be a long way away (from stable), there are still breaking changes coming in refractors, right? So alpha would require some to migrate again and again, and therefore I personally wouldn't actually use the alpha in a live project (e.g. at work) and miss out on speed of a stable compiler. I think @3flex can comment on the complexity of cherry, based on the above comment it's 3 small PRs, however with one of them forcing language version, does it mean we wouldn't benefit from K2's improvements?

@3flex

3flex commented Jun 9, 2024

Copy link
Copy Markdown
Member Author

Language version 1.9 limitation applies to compiler plugin only. The CLI and Gradle in theory get speedups but I haven't tested anything.

Cherry picking sounds like a good plan.

@karolgil

Copy link
Copy Markdown

Looking forward to using detekt in a project using Kotlin 2.0, happy to be a guinea pig.

Do you see any chances of publishing alpha or even a safe snapshot version for testing? Or maybe you have a timeline for when that might happen?

@baseballyama

Copy link
Copy Markdown
Contributor

I have successfully updated my company’s project to Kotlin 2.0, including the compiler plugin. However, we are currently blocked by detekt not supporting Kotlin 2.0.
I’m concerned that the longer detekt lacks support for Kotlin 2.0, the fewer users and new adopters we will attract.
Is there a way we can release a version that supports Kotlin 2.0?
Please let me know if there’s anything I can do to assist.

@BraisGabin

Copy link
Copy Markdown
Member

detekt WORKS with Kotlin 2.0. If it doesn't work for you then it's probably an issue in your configuration. If you need help you can use the discussions.

@karolgil

Copy link
Copy Markdown

Interesting.

I simply added id("io.gitlab.arturbosch.detekt") version "1.23.6" to the plugins section of my build.gradle.kts. Now when I try running ./gradlew detekt I'm seeing the following:

Starting a Gradle Daemon (subsequent builds will be faster)
> Task :detekt FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':detekt'.
> Invalid value (22) passed to --jvm-target, must be one of [1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 30s
1 actionable task: 1 executed

This matches the problem raised in #7382, for which the solution was apparently this PR that I don't think was released yet?

@3flex

3flex commented Jul 12, 2024 •

Copy link
Copy Markdown
Member Author

You can use snapshot versions until there's a new release that has Kotlin 2 built in to get around the JVM issue.

The compiler plugin works with Kotlin 2 but only if the language version is 1.9 and lower. That gap is tracked in #7304.

@baseballyama

Copy link
Copy Markdown
Contributor

@BraisGabin

detekt WORKS with Kotlin 2.0

Does this mean it works with the snapshot version? Or does it also support version 1.23.6?
If you mean support is only in the snapshot version, could you backport this PR to 1.23.6 and release 1.23.7? (Or rather, can I send the patch myself?)
As the number of users of the snapshot version increases, we expect more complaints about temporary breakages and destructive changes in the main branch. Users do not want to be affected by these issues. (I'm sorry if this concern didn’t exist.😅)

@BraisGabin

Copy link
Copy Markdown
Member

The current stable version of detekt works with kotlin 2.0

@karolgil

Copy link
Copy Markdown

The current stable version of detekt works with kotlin 2.0

To recap, because I think I'm just not expressing my issues correctly - detekt works with Kotlin 2.0, it doesn't work with language versions higher than 1.9 and that won't be solved until #7304 is merged and released.

In the meantime the best bet for folks in my situation is to build and use a snapshot version.

Is that correct?

@TWiStErRob

Copy link
Copy Markdown
Member

@karolgil I think the compiler and detekt language versions don't have to match, because there are no new language features in 2.0, unless you're using the compiler plugin, which is not the default when you use Detekt Gradle Plugin as far as I know. Other than the Java 22 issue, are you facing actual problems using detekt 1.23.6 in a Kotlin 2 project?

@BraisGabin

Copy link
Copy Markdown
Member

Or does it also support version 1.23.6?

I use 1.23.6 with kotlin 2.0 without any problem. So, what I mean, is that the church stable version of detekt already supports kotlin 2.0.

@baseballyama

Copy link
Copy Markdown
Contributor

I use 1.23.6 with kotlin 2.0 without any problem. So, what I mean, is that the church stable version of detekt already supports kotlin 2.0.

Now I can also use detekt 1.23.6 with Kotlin 2.0, but I need to use Kotlin v1 for detekt.
Is this the same situation as yours, @BraisGabin?

This is my gradle.kts configuration.

project.afterEvaluate {
    configurations.matching { it.name == "detekt" }.all {
        resolutionStrategy.eachDependency {
            if (requested.group == "org.jetbrains.kotlin") {
                useVersion("1.9.23")
            }
        }
    }
}

@BraisGabin

Copy link
Copy Markdown
Member

I don't use spring boot so I don't need that. But yes. That's expected.

@karolgil

Copy link
Copy Markdown

I got it to work.

Initially I was following the getting started documentation but today I decided to take a look at the README. After adding the following

tasks.withType<Detekt>().configureEach { jvmTarget = "21" }

the ./gradlew detekt worked and listed all issues found in the project.

I guess I don't have to understand the details of it but I'm still confused as to why that's needed.
Kudos to @baseballyama because that code sample was a good pointer to try to fiddle with jvm settings for detekt.

@BraisGabin

Copy link
Copy Markdown
Member

I guess I don't have to understand the details of it but I'm still confused as to why that's needed.

That is not longer needed on detekt 2.0 (current SNAPSHOT). But for 1.0 you need to set up that. Also, if there is anything in the documentation that isn't clear, please, could you open a PR updating it so the next one doesn't find the same issue?

@3flex 3flex mentioned this pull request Jul 22, 2024
@shuhuang-faire

Copy link
Copy Markdown

Hi, is the snapshot version also recommended for ruleset maintainers? I see quite some compilation errors after upgrading from 1.23.6 to main-SNAPSHOT. Just wonder if we should fix these errors now or wait until the stable release is out.

@BraisGabin

Copy link
Copy Markdown
Member

The apis are still not stable so they can still change.

But, it would be great if you can update and provide us feedback about how the new apis feel.

@shuhuang-faire

Copy link
Copy Markdown

Thanks Brais. If we use the snapshot version, it would be best to stick to a specific date to prevent our pipeline from breaking due to unexpected API changes. I noticed that the earliest version in the snapshot repository is from 8/28. Does the repository have a short retention period?

@cortinico

Copy link
Copy Markdown
Member

Does the repository have a short retention period?

That depends on Sonatype's retention period (we don't control it)

@shuhuang-faire

Copy link
Copy Markdown

Thanks. Do you have a rough estimate when we can expect a stable version of it?

@cortinico

Copy link
Copy Markdown
Member

Thanks. Do you have a rough estimate when we can expect a stable version of it?

We're going to release this in 1.23.7 as soon as we fix the last remaining issues we have with the CI

This branch was successfully deployed

1 active deployment
Preview — 73c8d7ec Deployed May 21, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build dependencies Pull requests that update a dependency file notable changes Marker for notable changes in the changelog parser pick request Marker for PRs that should be ported to the 1.0 release branch rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Jvm 22 K2 compiler crashes Detekt