Example: Using Maven 3 lifecycle extension

Lifecycle Extension Points

You can extend multiple classes depending on your needs:

Build Your Extension

Create a Maven project with a dependency on org.apache.maven:maven-core:3.9.9 and other dependencies:

    <groupId>org.apache.maven.extensions</groupId>
    <artifactId>beer-maven-lifecycle</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-core</artifactId>
      <version>3.9.9</version>
      <scope>provided</scope> <!-- always provided by the Maven Core Classloader -->
    </dependency>

    <!-- dependency for JSR 330 annotation -->
    <dependency>
      <groupId>javax.inject</groupId>
      <artifactId>javax.inject</artifactId>
      <version>1</version> 
      <scope>provided</scope> <!-- always provided by the Maven Core Classloader -->
    </dependency>

Create your extension class; your extension must be a Sisu component, therefore mark it with the JSR 330 (or legacy Plexus container) annotation:

@Named( "beer")
@Singleton
public class BeerMavenLifecycleParticipant extends AbstractMavenLifecycleParticipant
{

    @Override
    public void afterSessionStart( MavenSession session )
        throws MavenExecutionException
    {
      // start the beer machine
    }


    @Override
    public void afterProjectsRead( MavenSession session )
        throws MavenExecutionException
    {
      // ask a beer to the machine
    }

}

Generate Sisu index files during the build of your extension jar:

  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.eclipse.sisu</groupId>
        <artifactId>sisu-maven-plugin</artifactId>
        <version>0.3.5</version>
        <executions>
          <execution>
            <id>generate-index</id>
            <goals>
              <goal>main-index</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>

Load Your Extension

Use your extension in your build(s) via one of the means outlined at Guide to using Extensions

Whether late registration is sufficient or early registration is required depends on the implemented interface/extended class, e.g. AbstractMavenLifecycleParticipant.afterSessionStart() is not called for components registered late.