Demo of Maven Core Extensions:
Code provided here demoes one specific type of extension: Maven 3 lifecycle extension, and the different results obtained when injecting this extension in the different ways available.
Maven lifecycle participation can be provided through 3 APIs:
This study implements each API (see javadoc) then tests implementations in ITs that configure the extension in different ways: verification done after IT execution checks expected differences (see ITs results).
A Maven core extension is a library that goes into Maven Core classloader, then is really in the core execution of Maven, unlike a plugin that runs in a child classloader separated from other plugins.
There are multiple reasons one wants to put his code in Maven Core classloader:
There are multiple methods available to declare a library as an extension:
Declaring an extension in POM is the most classical and flexible way to do: the only drawback is that the extension is activated after POM reading, which can be too late for some very specific use cases like EventSpy.
Installing an extension directly inside Maven installation avoids the previous limitation, but is not flexible.
-Dmaven.ext.class.path=[path to files] is a little bit more flexible, but remains not configured into the build, which is not suitable to ensure an extension is available at build time.
.mvn/extensions.xml is the ultimate solution for these use cases. Its only drawback is that it has been added only in Maven 3.3.1.