[英]Dagger 2 no classes generated
I want to try something new and use Dagger 2 as my DI framework.我想尝试一些新的东西并使用 Dagger 2 作为我的 DI 框架。 So I have the following pom and the "hello world" coffee maker classes ( http://google.github.io/dagger/ ) in my projekt.所以我的项目中有以下 pom 和“hello world”咖啡机类( http://google.github.io/dagger/ )。
But when I do a mvn clean install no classes get generated.但是当我执行 mvn clean install 时,没有生成任何类。 As far as I unterstood there should be a "Dagger_CoffeeShop" class generated.据我所知,应该生成一个“Dagger_CoffeeShop”类。 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>
For those using Gradle: Make sure you are referencing the Dagger dependencies as following:对于那些使用 Gradle 的人:确保您正在引用 Dagger 依赖项,如下所示:
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如果您遇到apt
不受支持的情况,请添加
1) Into module app\\build.gradle
: 1) 进入模块app\\build.gradle
:
apply plugin: 'com.neenbedankt.android-apt'
2) Into project \\build.gradle
: 2)进入项目\\build.gradle
:
buildscript {
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
I had the same problem, only with the release version 2.0.我有同样的问题,只有发布版本 2.0。
In my case the following two steps solved this problem:在我的情况下,以下两个步骤解决了这个问题:
Adding target/generated-sources/annotations
to my build path将target/generated-sources/annotations
到我的构建路径
Adding <forceJavacCompilerUse>true</forceJavacCompilerUse>
to the maven compiler plugin将<forceJavacCompilerUse>true</forceJavacCompilerUse>
到 maven 编译器插件
<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:也可以看看:
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.当我使用下载的 JAR 文件(在下面的 POM 文件中注释掉)时,我的也没有生成 Dagger_ 文件。 Once I added the repository to the POM, everything was working fine.将存储库添加到 POM 后,一切正常。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.