google / dagger

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

Dagger fails with Kotlin 1.5.10 #2675

Closed rpuxa closed 3 years ago

rpuxa commented 3 years ago

Kotlin: 1.5.10 Dagger: 2.35.1

I'm trying to migrate a project to the new kotlin version but keep getting this error:

2: Task failed with an exception.

==============================================================================

bcorso commented 3 years ago

Caused by: java.lang.NoSuchMethodError: com.squareup.javapoet.ClassName.canonicalName()Ljava/lang/String; at dagger.internal.codegen.langmodel.DaggerElements.getTypeElement(DaggerElements.java:128)

This looks like something is pulling in an older version of JavaPoet onto the classpath (ClassName#canonicalName() was recently add in JavaPoet v1.12.0).

Can you look at the list of dependencies (something like ./gradlew -p app dependencies) and verify where the older version of javapoet is coming from?

rpuxa commented 3 years ago

So I find out that this library uses 11th version of javapoet com.evernote:android-state-processor:1.4.1 What can I do with that and why this error shows only with Kotlin 1.5+ version?

bcorso commented 3 years ago

For upgrading versions of transitive dependencies you should be able to use Gradle's dependency constraints.

Though I'm still not quite sure why Gradle's default resolution strategy doesn't work, since it should use the highest version.