0
votes

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?

1
Do you have a beans.xml file in your library module? See this question/answer for more info: stackoverflow.com/a/55513723/742081Ladicek
@Ladicek oh dear, thank you very much. I´ve added an empty bean.xml into the META-INF/ directory of my library and it is working nowMarian Klühspies
Good! Let me copy my comment as an answer so you can mark the question as answered.Ladicek

1 Answers

1
votes

Do you have a beans.xml file in your library module? See this question/answer for more info: https://stackoverflow.com/a/55513723/742081