My project, project
, used to use HK2 for DI, and now I'm trying to migrate it to using dagger2. It depends on a library, lib
, which uses HK2 for DI. Dependencies are managed with Gradle.
One of my classes looks like:
package com.mine;
import lib.LibService;
import lib.LibType;
public class MyClass {
private final LibService<LibType> service;
@Inject
public MyClass(LibService<LibType> service) {
this.service = service;
}
//...
}
When I try to run the code, I get an error caused by HK2:
There was no object available for injection at SystemInjecteeImpl(requiredType=LibService<LibType>,parent=MyClass,...)
. Stepping through the debugger, I see that HK2 is processing the @Inject
annotation, instead of Dagger2. It's likely that my Dagger2 Modules, Components, etc. are not exactly right, and I need to fix that. Regardless, I do not want HK2 "processing" the @Inject
on the constructor of MyClass
. To make things harder, there are many other transitive dependencies from lib
that I want, such as javax.ws.rs.POST
.
I tried removing HK2 from my dependencies, but this causes an error Caused by: java.lang.ClassNotFoundException: org.glassfish.hk2.utilities.binding.BindingBuilder
from inside lib
.
configurations.all {
exclude group: 'org.glassfish.hk2'
}
How can I set up Gradle to use hk2 for lib
, but NOT for MyClass
or other things in project
, while including other transitive dependencies from lib
that I want?