Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dagger 2 no classes generated

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>
like image 684
KIC Avatar asked Jan 13 '15 13:01

KIC


2 Answers

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'
    }
}
like image 99
riwnodennyk Avatar answered Sep 30 '22 23:09

riwnodennyk


I had the same problem, only with the release version 2.0.

In my case the following two steps solved this problem:

  • Adding target/generated-sources/annotations to my build path

  • Adding <forceJavacCompilerUse>true</forceJavacCompilerUse> to the maven compiler plugin

      <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <dependencies>
              <dependency>
                  <groupId>com.google.dagger</groupId>
                  <artifactId>dagger-compiler</artifactId>
                  <version>2.0</version>
              </dependency>
          </dependencies>
          <configuration>
              <source>1.8</source>
              <target>1.8</target>
              <!-- workaround for https://issues.apache.org/jira/browse/MCOMPILER-202 -->
              <forceJavacCompilerUse>true</forceJavacCompilerUse>
          </configuration>
      </plugin>
    

See also:

  • https://github.com/google/dagger/pull/103
  • https://issues.apache.org/jira/browse/MCOMPILER-202
like image 20
Sebastian S Avatar answered Sep 30 '22 23:09

Sebastian S