What are Maven build extensions, and how do they differ from plugins?
answer
- plugins = goals; extensions = machinery
- .mvn/extensions.xml loads before pom
- packaging + lifecycle + wagon
- Sisu/Plexus component wiring
- polyglot needs core extension
basics
~10 sExtensions are add-ons that plug into Maven's core to add capabilities like new packaging types, lifecycles, or transport protocols. Unlike plugins, which run goals during a build, extensions participate in how Maven itself works.
solid answer
~40 sA plugin contributes goals you bind to lifecycle phases (e.g. compiler:compile). A build extension instead augments Maven's core runtime: it can register a custom packaging type, contribute a new lifecycle mapping, add a wagon transport provider for a new repository protocol, or hook into component (Plexus/Sisu) wiring. Declared classically inside <build><extensions> in a pom, they share the project's classloader. Maven 3.3+ added <build><extensions> with isolation plus core extensions via .mvn/extensions.xml, which load even earlier — before the pom is read — so they can affect project loading itself (e.g. polyglot Maven, the Takari smart builder). So: plugins extend the build's work; extensions extend Maven's machinery.
code
xml · 8 lines<!-- .mvn/extensions.xml: loaded before the POM is read -->
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0">
<extension>
<groupId>io.takari.maven</groupId>
<artifactId>takari-smart-builder</artifactId>
<version>0.6.1</version>
</extension>
</extensions>go deeper
Knows extensions add capabilities to Maven beyond ordinary plugins.
Can name the two declaration mechanisms and that extensions affect Maven's core, not just goals.
Understands load order, classloader/component-wiring implications, and when each mechanism is required.
Governs extension usage across a monorepo, weighs build-machinery customization vs. maintainability and reproducibility.
## What an extension is Maven is built from small components wired together by an IoC container (historically Plexus, now Sisu/Guice). Most users customize a build with **plugins** — units that expose **goals** (like `compiler:compile`) which you bind to **lifecycle phases**. A **build extension** is different: it injects code into Maven's own runtime so it can change *how Maven behaves*, not just *what work runs*. Extensions can: - Register a new **packaging type** and its **lifecycle mapping** (which goals run in which phases). - Provide a **wagon** — a transport provider for a repository protocol Maven doesn't ship (e.g. `scp`, `webdav`, custom). - Replace or augment core components (artifact resolution, the build sequencer, etc.). - Enable **polyglot Maven** (writing the build model in YAML/Groovy/Kotlin instead of `pom.xml`). ## Two ways to declare them ### 1. Classic build extensions (`<build><extensions>`) Declared in the POM, loaded when the project is built, sharing (in older Maven) the build classloader: ```xml <build> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ssh</artifactId> <version>3.5.3</version> </extension> </extensions> </build> ``` ### 2. Core extensions (`.mvn/extensions.xml`) Since Maven 3.3.1, placed in the project's `.mvn/` directory. These load **before the POM is parsed**, so they can affect project loading itself — required for polyglot Maven and smart-builder extensions: ```xml <extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0"> <extension> <groupId>io.takari.maven</groupId> <artifactId>takari-smart-builder</artifactId> <version>0.6.1</version> </extension> </extensions> ``` ## Key contrast | | Plugin | Extension | |---|---|---| | Adds | Goals run during the build | Core capability / behavior | | Bound to | Lifecycle phases | Maven runtime wiring | | Typical use | compile, test, package, deploy | new packaging, transport, polyglot | Load order matters: core extensions (`.mvn/extensions.xml`) load earliest, then classic `<build><extensions>` when the project builds.
- Why must polyglot Maven be a core extension rather than a build extension?Because the build model (the alternative to pom.xml) must be parsed before the project is loaded; only .mvn/extensions.xml loads early enough to intercept project loading.
- Where do classic build extensions get declared?Inside <build><extensions><extension>...</extension></build> in the pom.xml.
Plugins are appliances you plug into the wall; extensions rewire the house's electrical panel.
saying these in an interview costs you the question
- Saying extensions are just another name for plugins.
- Claiming all extensions are declared in pom.xml (core extensions live in .mvn/extensions.xml).
- Thinking extensions bind to lifecycle phases like goals do.