liveBook · Manning

Quarkus extension

As explained in Quarkus in Action

A Quarkus extension is an integration component that adds framework-aware build-time and runtime support for a capability or library.

A Quarkus extension is a pluggable module that integrates a library or framework with Quarkus. Add only the capabilities an application needs instead of packaging a monolithic set of integrations. This reduces packaged code and resources, helping startup time and memory use. section 2.7.1 section 2.7

An extension can contribute at build time, at runtime, or both. Its integration code can perform initialization, add configuration properties, and supply information needed for native compilation. For example, an extension can register classes that its library accesses reflectively, sparing application developers much of that native-image configuration. A library does not always need its own extension, but an extension can make using it considerably easier. section 2.7.2 section 12.0 section 12.1.8

To use an existing extension:

  • Find candidates with `quarkus extension list --installable`; categories can narrow the search, such as `quarkus extension list --installable --category "messaging"`. section 2.7.3
  • Add one with `quarkus extension add "quarkus-messaging-kafka"`. Quarkus adds its Maven dependency; use `quarkus extension list` to see installed extensions or `quarkus extension remove` to uninstall one. section 2.7.3

A custom extension usually has two Maven modules: a deployment artifact used during the build and a runtime artifact included on the application's runtime classpath. Deployment processors run build steps that exchange build items; they can scan indexed application classes and invoke recorders to produce bytecode needed at runtime. Configuration can distinguish build-time properties from runtime properties. A value already acted on during the build cannot be changed effectively when the application starts. section 12.6 section 12.1.3

A metadata extension

A small custom extension adds an HTTP endpoint returning an application's name, version, and runtime dependencies as JSON. Build and install the extension with `mvn install`, then add its dependency to a Quarkus application. Calling `/metadata` verifies the endpoint; setting `quarkus.metadata.path=/some-other-path` and restarting moves it to the new path. Tests can check both the returned data and the configurable path. section 12.3 section 12.3.6 section 12.5

Custom extensions are an advanced option, not a requirement for every library. Before creating one for shared use, check whether a similar extension already exists in Quarkiverse. Extension-writing options extend beyond these basics. section 12.0 section 12.2

How Quarkus in Action covers it

How deep it goes
Works through extension management and a custom implementation, including deployment and runtime modules, build steps, configuration, and tests; defers exhaustive options.
Examples
Uses REST and Kafka extension dependencies, then builds a metadata endpoint returning application details and runtime dependencies.
What it assumes
Assumes a Quarkus application and familiarity with dependencies, while introducing extension structure before the advanced custom example.
What you can do after
Build it from scratch as a custom metadata extension, or operate/configure existing extensions through the Quarkus CLI.
How it connects
Connects Maven dependencies, dependency injection, build-time processing, Dev Services, and GraalVM native compilation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.