[英]The generated class for Component of Dagger 2 is not found in compileTestJava of Gradle's Java Plugin
[英]Dagger component not found error in Java?
public class ToInject {
public int val = 0;
public ToInject(){
System.out.println("Default");
}
}
@Module
public class ToInjectModule {
@Provides
@Singleton
public ToInject provideToInject(){
return new ToInject();
}
}
@Component(modules = ToInjectModule.class)
public interface ToInjectModuleComponent {
WillGetInjected willGetInjectedMaker();
}
public class WillGetInjected {
private ToInject toInject;
@Inject
public WillGetInjected(ToInject toInject){
this.toInject = toInject;
System.out.println(this.toInject.val);
}
}
我正尝试将ToInject
注入WillGetInjected
,如上所示。 我有一个ToInjectModule
和als ToInjectModuleComponent
所以我完全完全按照说明进行操作。 我也进口了
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger</artifactId>
<version>2.0</version>
</dependency>
但是当我执行mvn compile
时,我总是收到此错误:
Fatal error compiling: java.lang.NoClassDefFoundError: dagger/Subcomponent$Builder: dagger.Subcomponent$Builder -> [Help 1]
知道发生了什么,为什么?
有两个失踪案。
dagger compiler
添加到pom.xml
( Link ) <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.x</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
annotation scope
添加到组件中。 ( 链接请参见Singletons and Scoped Bindings
) @Component(modules = ToInjectModule.class)
public interface ToInjectModuleComponent {
WillGetInjected willGetInjectedMaker();
}
至
@Singleton
@Component(modules = ToInjectModule.class)
public interface ToInjectModuleComponent {
WillGetInjected willGetInjectedMaker();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.