quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.4k stars 2.57k forks source link

UnsatisfiedResolutionException with basic extension using Gradle and Kotlin #40961

Open cthiebault opened 1 month ago

cthiebault commented 1 month ago

Describe the bug

I'm trying to create a very simple Quarkus Extension using Gradle and Kotlin.

The extension is basic and just offer a CDI bean.

class ExtensionProcessor {
  @BuildStep
  fun feature(): FeatureBuildItem {
    return FeatureBuildItem(FEATURE)
  }

  @BuildStep
  fun registerBeans(): AdditionalBeanBuildItem {
    return AdditionalBeanBuildItem.builder()
      .addBeanClass(ExampleService::class.java)
      .build()
  }

  companion object {
    private const val FEATURE = "example-extension"
  }
}

Building the project, I get a

jakarta.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type com.example.ExampleService and qualifiers [@Default]
        - injection target: parameter 'exampleService' of com.example.application.ExampleResource constructor
        - declared on CLASS bean [types=[com.example.application.ExampleResource, java.lang.Object], qualifiers=[@Default, @Any], target=com.example.application.ExampleResource]

It works when I use Gradle + Java but not with Gradle + Kotlin.

How to Reproduce?

I've created a sample repo to reproduce the error: https://github.com/cthiebault/quarkus-gradle-kotlin-extension

Output of java -version

21.0.2

Quarkus version or git rev

3.11.0

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle 8.6

quarkus-bot[bot] commented 1 month ago

/cc @geoand (kotlin), @glefloch, @quarkusio/devtools

geoand commented 1 month ago

This is probably fixable, but I'll just say that what you are trying to do is completely untested and will likely never be officially supported.

cthiebault commented 1 month ago

This is probably fixable, but I'll just say that what you are trying to do is completely untested and will likely never be officially supported.

Thanks for your answer.

I've been using Quarkus with Gradle & Kotlin with success for 2 years now :-) Now that the projects become more complex, I need to extract common code to extensions... and I start to hit walls :-(

I thought as Quarkus supports Gradle and Kotlin that the extension would also work out of the box...

geoand commented 1 month ago

I thought as Quarkus supports Gradle and Kotlin that the extension would also work out of the box...

It does, but for writing applications, not extensions.

That said, I am pretty sure that this issue is solvable, but you are bound to run into more since this is completely uncharted territory.

mschorsch commented 1 month ago

@cthiebault We use Gradle + Kotlin for our applications, but we use Maven + Kotlin for our extensions. This combination has worked well for us.

You can find an example in the quarkiverse: https://github.com/quarkiverse/quarkus-mockk

@geoand The Quarkus documentation explicitly mentions Gradle extensions as supported (https://quarkus.io/guides/writing-extensions#using-gradle), so this seems a valid issue. Edit: My fault, it mentions Gradle but not Kotlin.

mschorsch commented 1 month ago

@cthiebault If you want I can provide a template for an extension with Maven + Kotlin.

geoand commented 1 month ago

@mschorsch right, that combination is totally untested AFAIk

aloubyansky commented 1 month ago

@mschorsch i think it'd be great

mschorsch commented 1 month ago

Here is an example of a Quarkus extension with Maven+Kotlin based on the standard example “Greeting extension”: quarkus-extension-kotlin-maven-skeleton.zip

Hope this helps.

cthiebault commented 1 month ago

Thanks your help :)

I'm working on an AWS Rest Lambda application using Gradle+Kotlin. As we cannot mix quarkus-amazon-lambda-rest with other non-REST lambda (like SQS), I'm splitting my application into 2 differents Quarkus applications with the common code as an extension:

I was hoping to be able to use a single Gradle project with 4 sub-projects... Using Maven for the extension and Gradle for the apps will complexify things. I may switch to Maven for this project. I'll have a look to your skeleton! Thanks again @mschorsch!