ursus
09/30/2025, 1:11 PManvil user.
Now I want to experiment with KMP.
I want to keep @Inject and @ContributesBinding.. in common - and expect-actual them to typealiases of the jvm libs (and therefore have anvil/dagger take effect only on jvm)
@Inject is easy enough
@Target(
FUNCTION,
PROPERTY_GETTER,
PROPERTY_SETTER,
CONSTRUCTOR,
FIELD
)
@Retention(RUNTIME)
@MustBeDocumented
expect annotation class Inject()
actual typealias Inject = javax.inject.Inject
but I'm having trouble with @ContributesBinding because of all the params. See the full issue in threadursus
09/30/2025, 1:19 PMexpect enum class ContributesBindingPriority { NORMAL, HIGH, HIGHEST }
@Target(CLASS)
@Retention(RUNTIME)
@Repeatable
expect annotation class ContributesBinding(
val scope: KClass<*>,
val boundType: KClass<*> = Unit::class,
val replaces: Array<KClass<*>> = [],
@Deprecated("Use the new int-based rank")
val priority: ContributesBindingPriority = ContributesBindingPriority.NORMAL,
val ignoreQualifier: Boolean = false,
// Use the literal default to avoid needing an expect companion
val rank: Int = Int.MIN_VALUE
)
I simply copy pasted the annotation source & created my own priority enum
and then
actual typealias ContributesBindingPriority = com.squareup.anvil.annotations.ContributesBinding.Priority
actual typealias ContributesBinding = com.squareup.anvil.annotations.ContributesBinding
but I'm getting
e: file:///Users/.../base-di/src/jvmMain/kotlin/foo/bar/di/Shims.jvm.kt:11:1 Parameter 'boundType' has conflicting values in expected and actual annotations.
e: file:///Users/.../base-di/src/jvmMain/kotlin/foo/bar/di/Shims.jvm.kt:11:1 Parameter 'replaces' has conflicting values in expected and actual annotations.
e: file:///Users/.../base-di/src/jvmMain/kotlin/foo/bar/di/Shims.jvm.kt Parameter 'priority' has conflicting values in expected and actual annotations.
e: file:///Users/.../base-di/src/jvmMain/kotlin/foo/bar/di/Shims.jvm.kt Parameter 'ignoreQualifier' has conflicting values in expected and actual annotations.
e: file:///Users/.../base-di/src/jvmMain/kotlin/foo/bar/di/Shims.jvm.kt Parameter 'rank' has conflicting values in expected and actual annotations.
is this idea completely flawed or am I doing it wrong?ursus
09/30/2025, 4:34 PMPriority?ephemient
09/30/2025, 4:49 PMexpect annotation classursus
09/30/2025, 5:03 PM