Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to override default CredentialsProvider #658

Closed
SimonScholz opened this issue Aug 26, 2024 · 1 comment
Closed

Unable to override default CredentialsProvider #658

SimonScholz opened this issue Aug 26, 2024 · 1 comment

Comments

@SimonScholz
Copy link

When I try to override the com.google.api.gax.core.CredentialsProvider like this:

import com.google.api.gax.core.CredentialsProvider
import com.google.api.gax.core.NoCredentialsProvider
import io.quarkus.arc.profile.IfBuildProfile
import jakarta.enterprise.context.Dependent
import jakarta.enterprise.inject.Produces

@Dependent
class GcpConfig {

    @Produces
    @IfBuildProfile("dev")
    fun credentialsProvider(): CredentialsProvider {
        return NoCredentialsProvider.create()
    }
}

... I get the following exception:

 java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: jakarta.enterprise.inject.spi.DeploymentException: jakarta.enterprise.inject.AmbiguousResolutionException: Ambiguous dependencies for type com.google.api.gax.core.CredentialsProvider and qualifiers [@Default]
        - injection target: io.quarkiverse.googlecloudservices.pubsub.QuarkusPubSub#credentialsProvider
        - declared on CLASS bean [types=[io.quarkiverse.googlecloudservices.pubsub.QuarkusPubSub, java.lang.Object], qualifiers=[@Default, @Any], target=io.quarkiverse.googlecloudservices.pubsub.QuarkusPubSub]
        - available beans:
                - PRODUCER METHOD bean [types=[java.lang.Object, com.google.api.gax.core.CredentialsProvider], qualifiers=[@Any, @Default], target=com.google.api.gax.core.CredentialsProvider credentialsProvider(), declaringBean=io.quarkiverse.googlecloudservices.common.GcpCredentialProviderProducer]
                - PRODUCER METHOD bean [types=[java.lang.Object, com.google.api.gax.core.CredentialsProvider], qualifiers=[@Default, @Any], target=com.google.api.gax.core.CredentialsProvider credentialsProvider(), declaringBean=gcp.GcpConfig]
        at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1551)

IMHO the implemtation of GcpCredentialProviderProducer should use io.quarkus.arc.DefaultBean instead of jakarta.enterprise.inject.Default as depicted in this guide: https://quarkus.io/guides/cdi-reference#enable_build_profile

Also see

Otherwise I will not be able to specify my own CredentialsProvider, which I intend to use for my locally running pubsub emulator spinned up by docker compose.
What do you think?

@SimonScholz
Copy link
Author

Okay I found out myself how to do it.

This code allows me to make use of the NoCredentialsProvider in my Quarkus application:

import com.google.api.gax.core.NoCredentialsProvider
import jakarta.annotation.Priority
import jakarta.enterprise.inject.Alternative
import jakarta.inject.Singleton

@Alternative
@Priority(1)
class GcpCredentialsProvider {
    @Singleton
    fun credentialsProvider() = NoCredentialsProvider.create()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@SimonScholz and others