Using Extensions

Extensions are a way to add classes to either the Core Classloader (Core Extensions) or the Project Classloader (Build Extensions). This is necessary for adjusting Maven in a way that affects more than just one plug-in.

The mechanism allows extensions to either replace default Sisu components with custom ones or add new components which are used at run time. In addition one could also expose additional packages from the Core Classloader.

Extensions are typically used to enable Wagon providers, used for the transport of artifact between repositories, and plug-ins which provide lifecycle enhancements.

Loading Extensions

There are different means of loading extensions depending on the type. There are core extensions which are loaded early and build extensions which are loaded late. Some extensions require early loading as they fundamentally change Maven behaviour. An extension's documentation should indicate whether it provides a core or a build extension.

Core Extension

  • Registered via extension jar in ${maven.home}/lib/ext
  • Registered via CLI argument mvn -Dmaven.ext.class.path=extension.jar
  • Registered via .mvn/extensions.xml file

Build Extension

  • Registered via project->build->plugins->plugin with element extensions being set to true. This is useful for regular plug-ins carrying some extensions.

    Example:

    
    <project>
      ...
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
              ...
            </configuration>
          </plugin>
        </plugins>
      </build>
      ...
    </project>
    
  • Registered as build extension in project->build->extensions->extension

    Example:

    
    <project>
      ...
      <build>
        <extensions>
          <extension>
            <groupId>org.apache.maven.wagon</groupId>
             <artifactId>wagon-ftp</artifactId>
             <version>2.10</version>
          </extension>
        </extensions>
      </build>
      ...
    </project>