Hello, while using a custom named annotation `@Def...
# koin
g
Hello, while using a custom named annotation
@DefaultHttpClient
I had no problem bringing a specific dependency in a constructor of a class:
Copy code
@Single
internal class FirebaseAuthImpl(
    private val firebase: Firebase,
    private val firebaseSettings: Lazy<FirebaseSettings>,
    @param:DefaultHttpClient  val httpClient: Lazy<HttpClient>,
    private val json: Lazy<Json>,
) : FirebaseAuth { ... }
Now, using the same annotation in a function misses the annotation:
Copy code
@Single
    fun provideFirebaseAuth(
        firebaseApp: FirebaseApp,
        firebaseSettings: Lazy<FirebaseSettings>,
        @DefaultHttpClient httpClient: Lazy<HttpClient>,
        json: Lazy<Json>,
    ): FirebaseAuth {
        return createFirebaseAuth(
            firebaseApp = firebaseApp,
            firebaseSettings = firebaseSettings,
            httpClient = httpClient,
            json = json,
        )
    }
The error is the following:
Copy code
[ksp] --> Missing Definition for property 'httpClient : io.ktor.client.HttpClient' in 'com.domain.app.di.provideFirebaseAuth'. Fix your configuration: add definition annotation on the class.
What am I missing? πŸ€”
Looks like a bug in
2.1.0
because if I remove
arg("KOIN_CONFIG_CHECK", "true")
from the app, it then builds and run smoothly
When trying
2.2.0-RC1
, the issue still exists and another one appears that doesn't appear in `2.1.0`:
Copy code
Caused by: java.lang.IllegalStateException: can't find definition metadata for ComCompanyServicesUserDomainObserveCurrentUserUseCase on org.koin.ksp.generated._KSP_ComCompanyServicesUserDomainObserveCurrentUserUseCase
	at org.koin.compiler.verify.KoinConfigChecker.verifyDefinition(KoinConfigChecker.kt:244)
	at org.koin.compiler.verify.KoinConfigChecker.verifyDefinition(KoinConfigChecker.kt:210)
	at org.koin.compiler.verify.KoinConfigChecker.verify(KoinConfigChecker.kt:93)
	at org.koin.compiler.BuilderProcessor.process(BuilderProcessor.kt:118)
	at com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:562)
	at com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:560)
	at ksp.com.google.devtools.ksp.common.IncrementalContextBase.closeFilesOnException(IncrementalContextBase.kt:400)
	at com.google.devtools.ksp.impl.KotlinSymbolProcessing.execute(KotlinSymbolProcessing.kt:560)
The module setup is pretty simple, like any other one:
Copy code
@Module
@Configuration
@ComponentScan("com.company.services.user")
class UserServiceModule
With the class being setup as
Copy code
@Single
internal class ObserveCurrentUserUseCaseImpl(
    private val authRepository: AuthRepository,
    private val userRepository: UserRepository,
) : ObserveCurrentUserUseCase { ... }
Any help would be greatly appreciated πŸ™
a
working on it πŸ‘
❀️ 1
g
@arnaud.giuliani At the end I've gone back to
2.1.0
using the
@Provided
animation to fix that specific issue. It would be very nice to see an example of how to set
2.2.0
in a multi-module project using
@Configuration
only (without enabling the default module) where some dependencies are defined only at the app level and where other modules are using interfaces of those dependencies πŸ™
a
I'm preparing content around yes
❀️ 1
b
Hi @arnaud.giuliani, is there any update on this? I have same issue with 2.2.0 and gradle multi-module (multi-project) setup. The @Configuration marked modules from other gradle modules are not added to @KoinApplication automatically. When I added them manually - started working, but it skips the new "no manual wiring" experience from koin 2.2.0 😞. Would love to know how to do this without manual wiring.
πŸ’― 1
a
Can you check Koin Annotations 2.3.0 - just published it for 2.2.20 and latest KSP compat
b
Still same on 2.3.0 on my side. However I checked your example-cmp, where it is also multi-module setup and it somehow works without explicit module wiring in
@KoinApplication
. When analyzed the generated code for KoinApp.startKoin, it not adds
DataModule().module
in
koinConfiguration()
to
modules()
call - same as in my project. However, in example-cmp DI works, while in my project I'm getting
org.koin.core.error.NoDefinitionFoundException
for missing dependency from gradle module if I not put the koin module explicitly in
@KoinApplication
to force the generated
koinConfiguration()
to add it πŸ€”.
a
do you have Gradle visibility for your module?
b
not sure what you mean, but I'm adding the affected module with
implementation(project(":my-module"))
a
Module discvoery with @Configuration can be done if you have visibility on it at classpath level
πŸ‘€ 1
b
I'm using
buildSrc
so need some time for additional work, will try in the evening or tomorrow and will let U know, thanks!
πŸ‘ 1
ok I found that current state of example-cmp app works because the wiring is done by `AppModule`'s:
@Module(includes = [DataModule::class, ...])
and it not uses
@Configuration
on
DataModule
(which is in separate gradle module) for automatic loading in
@KoinApplication
. Annotating
DataModule
with
@Configuration
still not enables auto wiring, and we need to include it anyway manually, e.g. in
ViewModelModule
or
AppModule
like in current example code. Updated my project in similar way to add module includes where they are needed and it works now without providing modules in
@KoinApplication
, however
@Configuration
in other gradle modules than main
app
is not needed as not works for the purpose of auto module wiring. I'll explore later how
@Configuration
works in multi-module projects for configuration management purpose.
g
So it doesn't discover modules by itself... πŸ€”
πŸ‘ 1
b
...if they are in other gradle modules.
g
Yeah which is 100% the case in multi-module projects...
a
this version of Now in Android is using full Annotations 2.2 + @Configuration : https://github.com/kotzilla-io/nowinandroid_koin_annotations/tree/migation_koin_annotations_2.2_improved
πŸ‘€ 1
yes, the current example-cmp could use @Configuration in data module
b
Thank you for providing these examples, will check how it is being setup there
πŸ™ 1
People in Space uses @Configuration in same module that @KoinApplication, so same case that works on my side too. Your version of Nia indeed works across modules, but it was your magic hands doing it so not surprising πŸ™‚ this project seems a good playground to look for the missing puzzle, also very nice example of migration from Hilt, appreciate the work!
yes, the current example-cmp could use @Configuration in data module
Can you provide the example branch on how
example-cmp
would look with
@Configuration
used to wire the
DataModule
?
a
I will update the main one
❀️ 1
Yeah, seeing currently that main module can't look up in classpath. Checking about KSP regression
❀️ 1
I've seen something around
❀️ 1