It creates a new lifecycle, with a name, and specifies the phases. Each phase is named compile, clean etc, but the executions therein can have multiple custom goals. In this case we're defining the 'test' goal we defined in a plugin previously to run twice on the compile phase.
To run this lifecycle, we need an empty plugin, that specifies this lifecycle, with its goals, must be run:
It's saying in the @execute lifecycle='ourlifecycle' phase='compile' that we should run the ourlifecycle lifecycle, specificially the 'compile' phase. This then needs to be put in our components.xml file (which we looked at in the previous tutorial):
So when we get to the compile phase of our package, that then loads the LifecycleLoaderMojo plugin, which in turn loads our ourlifecycle lifecycle in its compile phase, which runs two instances of our 'test' goal.
Lifecycles package types are the values inbetween the packaging tags underneath the main project tag. They're normally jar, or similar, and define what to do on each compile, clean, package, etc phase. We can define our own, and run one of our plugin classes on a particular phase.
In src/main/resources/META-INF/plexus/components.xml create
It defines a component that is a lifecycle mapping, has the name ourlifecycle, is implemented using the DefaultLifecycle, and its configuration tag says it is overriding the compile phase with the plugin (defined groupdId:artifactId:goal) that we defined before. We can put multiple goals using commas.
Now if you mvn clean install this plugin we can use it elsewhere. Let's create a new project. It has nothing in it, except this pom.xml:
This is very similar to the last time we used our plugin in another pom. However, there's now no executions tag, as the plugin is executed as part for the compile cycle, as defined in our components.xml. And the extensions tag set to true allow us to use the lifecycle name, ourlifecyclepackage, in the packaging tag.
Now if you mvn clean package, you'll see the plugin is executed, displaying the configured HALLO text. Note, although we only defined a compile phase in our components.xml, we still get the defaults from the superpom, 'package' in this case. We only overrode the compile phase.
The build tag has a plugin tag. Within we give it the group and artifact of the previously defined plugin, plus the version. The configuration is to pass the our.message parameter. We leave out the first part, for some reason. If we were setting this in the properties tag, under the project tag, we'd use our.message.
The execution tag says run the defined 'test' goal in the compile stage. And if we run mvn install, we'll see our output, 'HALLO' in this case, on the screen.