无法加载Maven、JUnit和Dagger-Dagger模块
注意:我仅通过命令行进行构建/测试 我在使用Dagger时遇到了一个问题,并且能够在一个非常小的测试项目中重现相同的问题。在单元测试中尝试使用Dagger时,我在运行“mvn clean test”时遇到以下错误:无法加载Maven、JUnit和Dagger-Dagger模块,maven,junit,dagger,Maven,Junit,Dagger,注意:我仅通过命令行进行构建/测试 我在使用Dagger时遇到了一个问题,并且能够在一个非常小的测试项目中重现相同的问题。在单元测试中尝试使用Dagger时,我在运行“mvn clean test”时遇到以下错误: sanity(com.mycompany.app.AppTest): Module adapter for class com.mycompany.app.AppTest$TestModule could not be loaded. Please ensure that code
sanity(com.mycompany.app.AppTest): Module adapter for class com.mycompany.app.AppTest$TestModule could not be loaded. Please ensure that code generation was run for this module.
在应用程序中,Dagger的编译/构建非常好,而注入工作非常好。唯一的问题是单元测试,我觉得单元测试没有从dagger编译器获取结果,但不确定如何测试/修复这个问题
pom.xml:
<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.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>my-app</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>com.squareup.dagger</groupId>
<artifactId>dagger</artifactId>
<version>1.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>1.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
啊哈-很明显,注释处理在之前的提交中完全关闭了,我完全错过了pom中的这一行:
<compilerArgument>-proc:none</compilerArgument>
-proc:none
我认为你应该在课堂上至少进行一次注射。应该为dagger编译器提供另一个范围如果这解决了您的问题,您可以接受自己的答案:)
<compilerArgument>-proc:none</compilerArgument>