Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to build quarkus application: Unsatisfied dependency for type

Tags:

java

quarkus

I'm trying to port a small corporate (multi module) RESTEasy JAX-RS application to Quarkus, but I'm hitting the error below. There a are a number of dependency on corporate modules over which I have no control, but I tried to follow Quarkus' context and dependency injection guide (https://quarkus.io/guides/cdi-reference).

OS: Ubuntu 18.04 (WSL)

Java: OpenJDK 11.0.8

Command: ./mvnw clean install -DskipTests

[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:1.9.2.Final:build (default) on project <REDACTED>: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR]         [error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: Found 4 deployment problems:
...
[ERROR] [3] Unsatisfied dependency for type <REDACTED>.security.cryptography.CryptographyService and qualifiers [@Default]
[ERROR]         - java member: <REDACTED>.request.handlers.ConfigurationFileDownloadHandler#cryptographyService
[ERROR]         - declared on CLASS bean [types=[<REDACTED>.request.handlers.ConfigurationFileDownloadHandler, java.lang.Object], qualifiers=[@Default, @Any], target=<REDACTED>.request.handlers.ConfigurationFileDownloadHandler]

The DI in the code itself:

...
import <REDACTED>.security.cryptography.CryptographyService;
...

@ApplicationScoped
public class ConfigurationFileDownloadHandler {

...

    @Inject
    private CryptographyService cryptographyService;
...

The dependency is declared in the sub-module pom file (as visible from mvn dependency:tree below):

[INFO] +- <REDACTED>.security.cryptography:cryptography-service-api-jar:jar:1.5.1:compile

I also created an application.properties file under <sub-module/src/main/resources with the following content:

quarkus.index-dependency.cryptography.group-id=<REDACTED>.security.cryptography
quarkus.index-dependency.cryptography.artifact-id=cryptography-service-api-jar

There is also an empty beans.xml file under ``<sub-module/src/main/resources/META-INF`.

Am I right to think that those third-party corporate classes don't have the proper annotation to be discovered by the Quarkus CDI process?

Any help appreciated.

like image 315
Emil Dimitrov Avatar asked Nov 29 '25 06:11

Emil Dimitrov


1 Answers

Am I right to think that those third-party corporate classes don't have the proper annotation to be discovered by the Quarkus CDI process?

Yes, this should be the issue, if no CDI annotation is present in the CryptographyService even if it's indexed by Jandex it will not be injectable.

The solution for this is to create a producer to produce a CryptographyService bean inside the bean factory.

Something like this:

@Singleton
public class CryptographyServiceProducer {
    @Produces
    @ApplicationScoped
    public CryptographyService cryptographyService() {
        return new CryptographyService();
    }
}

For reference, there is some documentation on CDI bean producer here: https://quarkus.io/guides/cdi#q-ok-you-said-that-there-are-several-kinds-of-beans

like image 119
loicmathieu Avatar answered Dec 01 '25 20:12

loicmathieu