Dagger 2 no classes generated

This isn't the best answer. When I used the downloaded JAR files (commented out in the POM file below) mine also wasn't generating the Dagger_ files. Once I added the repository to the POM, everything was working fine.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.hello</groupId>
  <artifactId>hellodagger</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>hellodagger</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <repositories>
    <repository>
      <id>sonatype</id>
      <name>sonatype-repo</name>
      <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
      <dependency>
        <groupId>com.google.dagger</groupId>
        <artifactId>dagger</artifactId>
        <version>2.0-SNAPSHOT</version>
        <!--<scope>system</scope>-->
        <!--<systemPath>${project.basedir}/dagger-2.0-20141216.223138-12.jar</systemPath>-->
      </dependency>
      <dependency>
        <groupId>com.google.dagger</groupId>
        <artifactId>dagger-compiler</artifactId>
        <version>2.0-SNAPSHOT</version>
        <optional>true</optional>
        <!--<scope>system</scope>-->
        <!--<systemPath>${project.basedir}/dagger-compiler-2.0-20141216.223201-12-jar-with-dependencies.jar</systemPath>-->
      </dependency>
  </dependencies>
</project>

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

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'
    }
}