google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.36k stars 2k forks source link

Feature request: Add support for K2 compiler. #4211

Open lubo-pisk opened 6 months ago

lubo-pisk commented 6 months ago

I have following configuration:

K2 Compiler Kotlin 2.0.0-Beta1 Dagger 2.50

kotlin.experimental.tryK2=true kapt.use.k2=true

Build failed with error:

error: annotation @SuppressLint is missing a default value for the element 'value'

Only Dagger uses kapt in my project.

Build is ok when kapt.use.k2=false.

bcorso commented 6 months ago

Do you have an example where this @SuppressLint usage is coming from?

I don't think Dagger uses @SuppressLint anywhere in our API or generated code, so it's unclear what we could do to fix this on our side.

dniHze commented 3 months ago

We don't see the same problem in our codebase. However, Dagger uses kotlinx-metadata to process Kotlin code in the kapt processor. In our project, compiling it with K2 KAPT enabled will produce NullPointer exception there. As Kotlin 2.0.0 comes with a new stable artifact for metadata processing, which makes it incompatible with the metadata generated with the K2/kapt. Resolving this requires an update to the newer artifact. I'm not so sure if the newer artifact will be backward compatible with K1-produced code though.