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 · 9 comments
Open

Kotlin K2 Support #546

mgroth0 opened this issue Jan 9, 2024 · 9 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

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

3 participants