I´m trying to get dependency injection working in my multi-module project where I want to inject a bean from a library module. However, it´s failing because it cannot find the bean.
project root settings.gradle
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}
include ':service-module'
include ':library-module'
service-module build.gradle
Tried compile, as well as implementation
dependencies {
compile project(":library-module")
// implementation project(":library-module")
}
Bean from library-module
import javax.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class LibraryBean {
public void hello() {
System.out.println("Hello");
}
}
service-module where injection happens
@ApplicationScoped
public class Application {
@Inject
LibraryBean libraryBean;
}
Stacktrace
Unsatisfied dependency for type com.mylibrary.LibraryBean and qualifiers [@Default] - java member: com.myservice.Application#LibraryBean - declared on CLASS bean [types=[com.myservice.Application, java.lang.Object], qualifiers=[@Default, @Any], target=com.myservice.Application]
I´m not sure if this issue is Quarkus-related or a general problem that exists with CDI and Gradle modules.
How can I make the DI working accross modules?
beans.xml
file in your library module? See this question/answer for more info: stackoverflow.com/a/55513723/742081 – Ladicek