Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Dagger in non-Android Gradle Java application?

Dagger is advertised as "A fast dependency injector for Android and Java". But I'm not able to make it run without Gradle 'android' plugin.

compile 'com.squareup.dagger:dagger:1.2.1'
provided 'com.squareup.dagger:dagger-compiler:1.2.1'

There is no provided in 'java' or 'application' gradle plugin I'm using. It is even mentioned in this bug report.

Making it both 'compile' yelds no result. The same java.lang.IllegalStateException: Module adapter for class ... could not be loaded. is thrown.

How gradle with 'java' and 'application' can be configured to use dagger annotation processor?

like image 783
atok Avatar asked Nov 29 '14 09:11

atok


1 Answers

It should work fine with both defined as compile. The error indicates other problem with your code.

If you still want to use provided scope please read this: http://www.sinking.in/blog/provided-scope-in-gradle/

Quick example how to use provided:

apply plugin: 'java'

configurations {
    provided
}

sourceSets {
    main {
        compileClasspath += configurations.provided
    }
}

dependencies {
    provided 'com.google.guava:guava:18.0'
}
like image 126
tomrozb Avatar answered Oct 20 '22 21:10

tomrozb