2

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?

Marian Klühspies
  • 15,824
  • 16
  • 93
  • 136
  • 1
    Do you have a `beans.xml` file in your library module? See this question/answer for more info: https://stackoverflow.com/a/55513723/742081 – Ladicek Jan 04 '20 at 13:34
  • @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 now – Marian Klühspies Jan 04 '20 at 13:54
  • Good! Let me copy my comment as an answer so you can mark the question as answered. – Ladicek Jan 04 '20 at 14:21

1 Answers1

3

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

Ladicek
  • 5,970
  • 17
  • 20