How can I get Kotlin working Dagger 2 and Intellij for non-android projects?


#1

I haven’t been able to get it working. I’m using the kapt plugin and calling “gradle build” will generate Dagger classes and compile as expected. The problem is that intellij doesn’t recognize the generated classes and can’t build the project. Has anyone gotten this working?


#2

You probably found the solution long ago, but for future searchers, just add this to your build:

  sourceSets {
    main {
      java {
        srcDir "${buildDir}/generated/source/kapt2/main"
      }
    }
  }

(Change kapt2 to kapt if you are not using the new experimental kapt2)


#3

Almost 1 year later and it’s still valid… This shouldn’t be done manually…


#4

I’ve made a basic Dagger 2 example in Kotlin that you should be able to import, compile and run in IntelliJ IDEA. Just see the readme, it’s easy.