https://kotlinlang.org logo
Join SlackCommunities
Powered by
# kotlin-inject
  • r

    ralf

    09/13/2024, 4:22 PM
    One more anecdote about the long release times, for that reason we maintain a fork internally (we can’t consume snapshot builds 🤦 ) and in other projects such as the open source Anvil plugin I must switch to snapshots in tests when it comes compiling components.
    laugh cry face palm 2
  • e

    evant

    09/13/2024, 6:11 PM
    Released kotlin-inject 0.7.2! This version has a whole bunch of bug fixes, particularly around the new qualifier support. Also updated to kotlin 2.0.0! https://github.com/evant/kotlin-inject/releases/tag/v0.7.2
    👏 8
  • z

    Zac Sweers

    09/15/2024, 3:40 AM
    using kotlin-inject in an app with iOS targets for the first time but seeing an odd behavior that seeeems to be the kotlin compilation missing some generated sources. The generated code all looks correct, and some of it is being compiled, but seemingly some of it (namely the anvil-generated contributions) are deemed to be missing and fail to compile even though they’re present in the same generated source set 🤔. Curious if anyone else has seen issues like this https://github.com/ZacSweers/FieldSpottr/pull/66
    r
    • 2
    • 3
  • j

    Josh Feinberg

    09/17/2024, 3:55 AM
    just updated to 0.7.2 and started migrating to use
    kotlin-inject-anvil
    and now i'm getting a
    FileAlreadyExistsException
    . best way to debug this?
    e
    b
    • 3
    • 5
  • m

    Marko Novaković

    09/19/2024, 11:54 AM
    I’m using
    kotlin-inject
    +
    kotlin-inject-anvil
    and my component is
    interface ApplicationComponent : ApplicationComponentMerged
    which is fine.
    ApplicationComponentMerged
    is generated but
    ApplicationComponent
    can’t access things provided by components that
    ApplicationComponentMerged
    extends/inherits
    ➕ 1
    r
    j
    z
    • 4
    • 13
  • j

    John O'Reilly

    10/03/2024, 4:16 PM
    probably basic question but running in to following and no additional info provided....is there some other log file for example that would provide more details about specific cause of this?
    Copy code
    e: [ksp] @Provides method must have a concrete implementation
    e: Error occurred in KSP, check log for detail
    e
    • 2
    • 5
  • r

    ralf

    10/23/2024, 9:37 PM
    Perhaps a question for #C013BA8EQSE, but how do you debug this error?
    Copy code
    e: [ksp] java.lang.IllegalArgumentException: Error type '<ERROR TYPE>' is not resolvable in the current round of processing.
            at com.squareup.kotlinpoet.ksp.KsTypesKt.requireNotErrorType(KsTypes.kt:40)
            at com.squareup.kotlinpoet.ksp.KsTypesKt.toTypeName(KsTypes.kt:71)
            at com.squareup.kotlinpoet.ksp.KsTypesKt.toTypeName(KsTypes.kt:199)
            at com.squareup.kotlinpoet.ksp.KsTypesKt.toTypeName(KsTypes.kt:196)
            at com.squareup.kotlinpoet.ksp.KsTypesKt.toTypeName$default(KsTypes.kt:187)
            at me.tatarka.kotlin.ast.KSAstType.toTypeName(KSAst.kt:555)
            at me.tatarka.kotlin.ast.AstParam.toParameterSpec(Ast.kt:269)
            at me.tatarka.inject.compiler.InjectGenerator.generateInjectComponent(InjectGenerator.kt:118)
            at me.tatarka.inject.compiler.InjectGenerator.generate(InjectGenerator.kt:68)
            at me.tatarka.inject.compiler.ksp.ProcessInjectKt.process(ProcessInject.kt:80)
            at me.tatarka.inject.compiler.ksp.ProcessInjectKt.processInject(ProcessInject.kt:28)
            at me.tatarka.inject.compiler.ksp.ProcessInjectKt.processInject$default(ProcessInject.kt:19)
            at me.tatarka.inject.compiler.ksp.InjectProcessor.process$lambda$1(InjectProcessor.kt:55)
    It’s likely that an
    api
    vs
    implementation
    dependency was misused. Is there an easy way to find out where this happens? E.g. print the file
    z
    • 2
    • 6
  • r

    ralf

    10/23/2024, 11:02 PM
    I’m testing the new KSP release. It seems like kotlin-inject can finally use KSP2 🎉
    👀 3
    K 4
    e
    a
    • 3
    • 3
  • j

    John O'Reilly

    10/24/2024, 3:13 PM
    Is there any particular approach recommended when using kotlin-inject with WorkManager? I see Tivi has for example custom
    WorkerFactory
    ...but had wondered if maybe something similar to
    @HiltWorker
    ?
    s
    • 2
    • 1
  • d

    Daniel Weidensdörfer

    11/02/2024, 10:42 AM
    Hello, is it right that creating multiple scope annotations for a component is useless?
  • r

    ralf

    11/02/2024, 11:14 PM
    Yes, a component can only have one scope. I filed this ticket some time ago and meant to contribute this feature, but given how kotlin-inject verifies scopes at the moment in super types this feature would be very confusing.
    👍 1
  • d

    Daniel Weidensdörfer

    11/08/2024, 11:01 AM
    Whats the best way to scope classes to some application value, like the current user?
  • r

    ralf

    11/08/2024, 9:02 PM
    You can create a “subcomponent”: https://github.com/evant/kotlin-inject?tab=readme-ov-file#component-inheritance
  • d

    Daniel Weidensdörfer

    11/08/2024, 9:15 PM
    I have figured something out already.
  • d

    Daniel Weidensdörfer

    11/08/2024, 9:55 PM
    Is there a way to bind a function to an interface? For example I have an expect function that returns a platform spcecific implementation of an interface.
  • j

    Josh Feinberg

    11/12/2024, 3:55 AM
    trying to update from kotlin-inject-anvil 0.0.5 to 0.1.0 and having an issue. i have a reproducible sample but i'm not sure if its just an issue with my coding or something broken in kotlin-inject or kotlin-inject-anvil
    e
    r
    • 3
    • 21
  • k

    Kirill Zhukov

    11/25/2024, 11:10 PM
    For
    kotlin-inject-anvil
    , should I expect
    FeatureFlagService
    and
    FeatureFlagSyncWorker
    to be singletons here?
    Copy code
    @Origin(value = FeatureFlagServiceImpl::class)
    @ContributesTo(scope = AppScope::class)
    public interface FeatureFlagServiceImplComponent {
      @Provides
      @SingleIn(scope = AppScope::class)
      public fun provideFeatureFlagService(implementation: FeatureFlagServiceImpl): FeatureFlagService = implementation
    
      @Provides
      @SingleIn(scope = AppScope::class)
      public fun provideFeatureFlagSyncWorker(implementation: FeatureFlagServiceImpl): FeatureFlagSyncWorker = implementation
    }
    r
    • 2
    • 10
  • j

    John O'Reilly

    12/22/2024, 10:22 AM
    Looking to migrate KMP project (https://github.com/joreilly/BikeShare) over to using
    kotlin-inject-anvil
    and just struggling a little with
    createComponent
    etc plumbing. I have per platform application components and can't do likes of following in those (expect function needs to be in
    commonMain
    ). Are there any examples on how to setup something like this?
    Copy code
    @MergeComponent.CreateComponent
    expect fun KClass<DesktopApplicationComponent>.createComponent(): DesktopApplicationComponent
    e
    h
    • 3
    • 12
  • d

    Daniel Weidensdörfer

    12/23/2024, 2:20 PM
    Is there a better way to create singletons than creating a new scope notation for each component?
    e
    m
    • 3
    • 9
  • p

    parth

    01/01/2025, 7:01 PM
    first time using kotlin-inject, and it’s pretty cool! I had to learn one the hard way…. could maybe be useful feedback for docs or FRs:
    @Provides
    methods need to be wrapped in a
    @Component
    , else they don’t get picked up. e.g.
    Copy code
    //in file network.kt
    @Provides
    fun provideOkhttpClient(): OkHttpClient {
        return OkHttpClient.Builder().build()
    }
    this won’t work, it needs to be
    Copy code
    @ContributesTo(AppScope::class) //k-i-anvil annotation
    interface NetworkComponent {
      @Provides fun okhttp(): OkHttpClient { ... }
    }
    FR: could be cool to allow
    @Provides
    on toplevel functions without a Component wrapper. Or have something in the docs for Dagger converts that says “use
    @Component
    like Dagger uses `@Module`”
    e
    • 2
    • 5
  • u

    ursus

    01/24/2025, 2:07 AM
    Hi, anyone care to share how is kotlin inject/anvil in production? I'm a 500kloc dagger/anvil app.
    e
    k
    • 3
    • 43
  • k

    Konstantin Tskhovrebov

    02/09/2025, 6:56 PM
    Hi! Do you know the reason? Or I missed something? https://github.com/evant/kotlin-inject/issues/464
    e
    • 2
    • 10
  • d

    dave08

    02/11/2025, 2:02 PM
    Hi! Wondering if I can gradually migrate to Kotlin Inject Anvil, or I have to do it all at once? It seems like I'm getting funny errors, and I'm not sure if it's connected to the fact that I have both in the same module (making different components).
    r
    • 2
    • 2
  • d

    dorche

    02/25/2025, 2:28 PM
    Hi, could someone help me figure out how to have the correct visibility modifiers when using kotlin-inject? Basically I have a KMP project with an Android and an iOS app consuming + shared module. I want my "Repositories" to have
    internal
    visibility modifier but I'm running into some issues. Details in thread
    m
    • 2
    • 7
  • a

    André Thiele

    03/04/2025, 3:21 PM
    when will be the 0.7.3 release? i see there was a snapshot release on jan 10th, since then no release. we have the 4th of march now and the last 0.7.2 release was in september 2024.
    ➕ 2
  • e

    eygraber

    03/13/2025, 4:11 AM
    Is it possible to create a "regular" kotlin-inject
    Component
    as a child of a kotlin-inject-anvil
    ContributesSubcomponent
    ? I tried doing this and it can't find any dependencies from the ancestor graphs.
    r
    • 2
    • 4
  • r

    ralf

    04/17/2025, 5:57 AM
    This is a blast from the past:
    Copy code
    Caused by: ksp.org.jetbrains.kotlin.analysis.api.lifetime.KaInvalidLifetimeOwnerAccessException: Access to invalid ksp.org.jetbrains.kotlin.analysis.api.platform.lifetime.KotlinAlwaysAccessibleLifetimeToken@33adf999: PSI has changed since creation
            at ksp.org.jetbrains.kotlin.analysis.api.fir.symbols.KaFirNamedFunctionSymbol.getPsi(KaFirNamedFunctionSymbol.kt:247)
            at com.google.devtools.ksp.impl.symbol.kotlin.UtilKt.toContainingFile(util.kt:237)
            at com.google.devtools.ksp.impl.symbol.kotlin.AbstractKSDeclarationImpl$containingFile$2.invoke(AbstractKSDeclarationImpl.kt:79)
            at com.google.devtools.ksp.impl.symbol.kotlin.AbstractKSDeclarationImpl$containingFile$2.invoke(AbstractKSDeclarationImpl.kt:78)
            at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:83)
            at com.google.devtools.ksp.impl.symbol.kotlin.AbstractKSDeclarationImpl.getContainingFile(AbstractKSDeclarationImpl.kt:78)
            at me.tatarka.kotlin.ast.KSAstProvider.addOriginatingElement(KSAst.kt:94)
            at me.tatarka.inject.compiler.KmpComponentCreateGenerator.generate(KmpComponentCreateGenerator.kt:27)
            at me.tatarka.inject.compiler.ksp.ProcessKmpComponentCreateKt.generateKmpComponentCreateFiles(ProcessKmpComponentCreate.kt:40)
            at me.tatarka.inject.compiler.ksp.InjectProcessor.finish(InjectProcessor.kt:113)
    I can reproduce this consistently in unit tests for all platforms where I define the function in
    commonTest
    Copy code
    @KmpComponentCreate
    expect fun createTestComponent(
      coroutineScope: CoroutineScope,
      coroutineDispatcher: CoroutineDispatcher,
    ): TestComponent
    This happens only with KSP 2, there’s no issue with KSP 1 obviously.
    e
    d
    • 3
    • 15
  • a

    Alexandre Gressier

    04/17/2025, 1:02 PM
    First time user of kotlin-inject-anvil, it’s been awesome so far! I do have a question: what is the correct approach regarding multi-module projects?
    b
    r
    • 3
    • 15
  • p

    Pablichjenkov

    04/24/2025, 7:58 PM
    Is there any demo project using kotlin-inject and compose navigation? More exactly I want to scope a subcomponent to a NavGraph or to the destination which represents a NavGraph. I am not sure about the ways to know when the NavGraph destination is created and when it is destroyed. So I could create and dispose of said subcomponent respectively. I have searched but nothing related came out
    k
    • 2
    • 4
  • j

    Josh Feinberg

    04/30/2025, 3:52 AM
    when updating to 0.8.0 i have a weird bug with typealias but i can't create a reproduction so not sure where is best to start debugging 🧵
    • 1
    • 4