Skip to content

Update docs to reflect that injection should not  #29605

@julgus

Description

@julgus

Description

Reading the chapter Starting a Service in the Quarkus extension guide I was led to believe that I can inject an instance of BuildProducer<NativeImageResourceItem> in my Processor.

However when injecting it as instructed in the docs, my native build fails with the following exception:

Caused by: java.lang.IllegalArgumentException: Producing values from constructors or fields is no longer supported. Inject the BuildProducer/Consumer through arguments of relevant @BuildStep methods instead. at io.quarkus.deployment.annotations.BuildProducer io.quarkiverse.jpastreamer.deployment.JpastreamerProcessor.resource of class io.quarkiverse.jpastreamer.deployment.JpastreamerProcessor
        at io.quarkus.deployment.ExtensionLoader.reportError(ExtensionLoader.java:997)
        at io.quarkus.deployment.ExtensionLoader.unsupportedConstructorOrFieldProducer(ExtensionLoader.java:974)
        at io.quarkus.deployment.ExtensionLoader.loadStepsFromClass(ExtensionLoader.java:431)
        at io.quarkus.deployment.ExtensionLoader.loadStepsFrom(ExtensionLoader.java:217)
        ... 50 more

Luckily the error is instructive enough that I understand that I should not rely on field injection, but rather pass the BuildProducer as an argument to my build step.

Still, I propose that the examples in the docs are updated to reflect this change to avoid fatal errors. Here is the full example I am referencing, from section 2.19.8.

public final class MyExtProcessor {
    @Inject
    BuildProducer<NativeImageResourceBuildItem> resource;
    @Inject
    BuildProducer<NativeImageResourceBundleBuildItem> resourceBundle;

    @BuildStep
    void registerNativeImageResources() {
        resource.produce(new NativeImageResourceBuildItem("/security/runtime.keys")); 

        resource.produce(new NativeImageResourceBuildItem(
                "META-INF/my-descriptor.xml")); 

        resourceBundle.produce(new NativeImageResourceBuildItem("javax.xml.bind.Messages")); 
    }
}

Implementation ideas

Update the documentation to reflect that field-injection of BuildProducer is no longer supported.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions