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

Kotlin K2 Support #546

Open
mgroth0 opened this issue Jan 9, 2024 · 17 comments
Open

Kotlin K2 Support #546

mgroth0 opened this issue Jan 9, 2024 · 17 comments

Comments

@mgroth0
Copy link

mgroth0 commented Jan 9, 2024

Testing Problem

I am testing with Kotlin K2 (Kotlin version 2.0.0-Beta2). I just discovered jqwik and wanted to play around with it and consider integrating it into my projects. The docs for kotlin say to include these compiler arguments:

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf(
            "-Xjsr305=strict", // For strict type warnings
            "-Xemit-jvm-type-annotations" // Required for annotations on type variables
        )
        jvmTarget = "11" // 1.8 or above
        javaParameters = true // Required to get correct parameter names in reporting
    }
}

I tried to add the two compiler arguments above, but then got the following warnings:

w: Flag is not supported by this version of the compiler: -Xjsr305=strict
w: Flag is not supported by this version of the compiler: -Xemit-jvm-type-annotations

This signals to me that jqwik does not yet have first class support for Kotlin 2, so I am hesitating to use it for now.

Suggested Solution

I suggest to add support for Kotlin 2. The documentation could be updated to say how the user should configure kotlin if they use K2, which would also reasure the user that K2 is supported.

@vlsi
Copy link
Contributor

vlsi commented Jan 9, 2024

I guess the mentioned flags are outdated, and they should be removed

@jlink
Copy link
Collaborator

jlink commented Jan 11, 2024

K2 is still in beta with the latest Kotlin release (1.9.22), isn't it.
My plan is to update to K2 as soon as it is the default, which I assume will be in Kotlin 2.0.

What if we use this issue to document the problems with K2 and the stuff that has to be changes, like dropping some compiler flags - and maybe adding others.

BTW, @mgroth0 What's the correct way to use K2 from Gradle with the current Kotlin release?

@vlsi
Copy link
Contributor

vlsi commented Jan 11, 2024

See https://kotlinlang.org/docs/whatsnew19.html#try-the-k2-compiler-in-your-project

./gradlew -Pkotlin.experimental.tryK2=true ...

@jlink
Copy link
Collaborator

jlink commented Jan 11, 2024

Thanks @vlsi .
A first try leads to many compilation errors. Arrgh.

@vlsi
Copy link
Contributor

vlsi commented Jan 11, 2024

The majority of compilation errors are caused by jsr305 annotations.

WDYT of completely removing jsr305 from jqwik?
For instance, https://github.com/jqwik-team/jqwik/blob/main/api/src/main/java/net/jqwik/api/NonNullApi.java effectively marks everything as non-null no matter if you specify it with jspecify.

@vlsi
Copy link
Contributor

vlsi commented Jan 11, 2024

I think you should be able to drop @NonNullApi (along with jsr305 dependency), and add @NullMarked at the package level: https://jspecify.dev/docs/user-guide#java-variables-are-references

@jlink
Copy link
Collaborator

jlink commented Jan 11, 2024

At least worth a try.

@mgroth0
Copy link
Author

mgroth0 commented Jan 17, 2024

Thank you both for looking into this and for giving K2 a shot.

I've been working with K2 for a month or so now. It's still unstable, and I've had to create workarounds for many issues. Sorry for dumping this on you guys. It might be smart to wait a few more months at least. I expect Jetbrains will have resolved many more issues by then.

@vlsi
Copy link
Contributor

vlsi commented Jan 17, 2024

jsr305 removal makes sense even without K2

@vlsi
Copy link
Contributor

vlsi commented May 22, 2024

Kotlin 2.0 has been released yesterday: https://kotlinlang.org/docs/whatsnew20.html

@jlink
Copy link
Collaborator

jlink commented May 23, 2024

That somehow strongly suggests to migrate to K2 with jqwik 1 rather sooner than later. I had hoped to defer that till version 2 :-/

@nym3r0s
Copy link
Contributor

nym3r0s commented May 27, 2024

@vlsi @jlink - I took a look at your comments and I've raised a quick PR. Let me know if there's anything to improve, thanks!

@jlink
Copy link
Collaborator

jlink commented May 27, 2024

@vlsi @jlink - I took a look at your comments and I've raised a quick PR. Let me know if there's anything to improve, thanks!

Thanks. I commented the PR over there.

@jlink
Copy link
Collaborator

jlink commented May 28, 2024

Published in 1.9.0-SNAPSHOT

@jlink jlink closed this as completed May 28, 2024
@SimY4
Copy link

SimY4 commented May 29, 2024

Could be just me, but it seems like -Xjsr305 property is still respected by the final version of the compiler.

Also, just wanted to check if always targetting the latest version of kotlin is intended? I assume that regardless of how good Kotlin devs are, some may obstain from updating to it immediately. So maybe setting a kotlinTarget to 1.9 would be a good idea?

@jlink
Copy link
Collaborator

jlink commented Jun 1, 2024

Could be just me, but it seems like -Xjsr305 property is still respected by the final version of the compiler.

Since jsr305 is no longer used this shouldn't affect jqwik's Kotlin module. But maybe I'm missing something.

@jlink
Copy link
Collaborator

jlink commented Jun 1, 2024

Also, just wanted to check if always targetting the latest version of kotlin is intended? I assume that regardless of how good Kotlin devs are, some may obstain from updating to it immediately. So maybe setting a kotlinTarget to 1.9 would be a good idea?

Frankly, I find the current state of how to set minimum and compilation versions of Kotlin in Gradle highly confusing. I just cannot find documentation that describes it sufficiently for me.

Anyways, I tried to set min target version to 1.9 and released it as a snapshot (`1.9.0-SNAPSHOT'). See e5ac104.
You might want to try it out.

@jlink jlink reopened this Jun 1, 2024
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

No branches or pull requests

5 participants