# dagger

Mikołaj Karwowski

10/25/2021, 9:59 AM
I tried creating a pure Kotlin/Gradle project in Intellij to play around with dagger (currently losing my mind over it lol) But even with very simple module/component it's not working as soon as I add a simple @provides or @binds annotation inside the module I get something along the lines of:
Copy code
[kapt] di.HeaterModule: Can't reference type 'Heater' from default package in Java stub.
as a warning and the error is:
Copy code
error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public abstract interface HeaterModule {
To be clear, this is my module:
Copy code
interface HeaterModule {

    //Tried both
//    @Binds
//    fun bindHeater(heater: SmallHeater): Heater
    fun provideHeater(): Heater {
        return SmallHeater()
The component that doesn't even do anything:
Copy code
@Component(modules = [HeaterModule::class])
interface TeaComponent{
//    fun teaMaker(): TeaMaker
And the cherry on the top where I suspect the errors to be, but can't find them i.e.
Copy code
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("kapt") version "1.5.31"
    kotlin("jvm") version "1.5.10"

group = "me.mkarwowski"
version = "1.0-SNAPSHOT"

kapt {
    generateStubs = true
    keepJavacAnnotationProcessors = true

repositories {

dependencies {
    implementation( "")
    annotationProcessor( "")
    kapt( "")


tasks.test {

tasks.withType<KotlinCompile>() {
    kotlinOptions.jvmTarget = "1.8"

application {
Am I doing anything obviously wrong here? I'll upload it to github in a second so You can reproduce it


10/25/2021, 10:04 AM
You definitely don’t need both
configurations, Dagger works just as well when running just in
I also don’t think
generateStubs = true
is still needed. Plus, you’re using different Kotlin and Kapt versions, which seems off

Mikołaj Karwowski

10/25/2021, 10:12 AM
Honestly, sometimes I hate dagger with passion. I've spent last 2 days on it and it started working right after I posted the question... 🤦‍♂️ And I have no clue why wasn't it working anyway
Anyway, Thank You for looking into it. You re right about the versions, I d never think it's correlated. About other things like annotationProcessor and generateStubs - first I tried without it but it's gotten to the point of desperate trying out old solutions lol
👍 1

Carl Benson

10/27/2021, 7:50 AM
Dagger comes with a steep learning curve and it is easy to hate (I did for a long time) before you learn it. Their hopelessly bad way of explaining it surely doesn't help (or we wouldn't have 1000+ articles titled "Dagger, the simple way...". But hang in there, when it finally drops, you'll realise that it is an extremely powerful and helpful tool
👍 1