Dagger 2 no classes generated

KIC picture KIC · Jan 13, 2015 · Viewed 7.3k times · Source

I want to try something new and use Dagger 2 as my DI framework. So I have the following pom and the "hello world" coffee maker classes (http://google.github.io/dagger/) in my projekt.

But when I do a mvn clean install no classes get generated. As far as I unterstood there should be a "Dagger_CoffeeShop" class generated. Hmmm ... what am I missing?

<modelVersion>4.0.0</modelVersion>

<groupId>kic</groupId>
<artifactId>xfoo</artifactId>
<version>0.1-SNAPSHOT</version>

<packaging>jar</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>com.google.dagger</groupId>
        <artifactId>dagger</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
</dependencies>


<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <dependencies>
                <dependency>
                    <groupId>com.google.dagger</groupId>
                    <artifactId>dagger-compiler</artifactId>
                    <version>2.0-SNAPSHOT</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

Answer

riwnodennyk picture riwnodennyk · Jun 11, 2015

For those using Gradle: Make sure you are referencing the Dagger dependencies as following:

compile 'com.google.dagger:dagger:2.0.2'
apt 'com.google.dagger:dagger-compiler:2.0.2'

And in the case if you are running into apt not supported, add

1) Into module app\build.gradle:

apply plugin: 'com.neenbedankt.android-apt'

2) Into project \build.gradle:

buildscript {
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}