I was going through a book that explain how to override 'default' lifecycle of Maven.
It says: To define a new lifecycle for a packaging type, you'll need to configure a LifecycleMapping component in Plexus. In your plugin project, create a META-INF/plexus/components.xml under src/main/resources. In components.xml add the content as shown below, and you're done. With below configuration, I'm able to customize the default lifecycle for 'jar' packaging type. Now If I exeute
$ mvn package
It straigh away executes 'package' phase skipping all other phases of default lifecycle and executes 'echo' goal of 'maven-zip-plugin'.
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>zip</role-hint>
<implementation>
org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
</implementation>
<configuration>
<phases>
<package>org.sonatype.mavenbook.plugins:maven-zip-plugin:echo
</package>
</phases>
</configuration>
</component>
</components>
</component-set>
My question is: How can I customize 'clean' lifecycle. For example, assume when some one types
$ mvn clean
Instead of running clean:clean that will execute 'clean' goal of 'maven-clean-plugin' plugin, I wanted to execute 'customClean' goal of 'customPlugin'.
There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project's web site.
A Maven lifecycle consists of a sequence of named phases: prepare-resources, compile, package, and install among other. There is phase that captures compilation and a phase that captures packaging.
The Maven Clean Plugin, as the name implies, attempts to clean the files and directories generated by Maven during its build. While there are plugins that generate additional files, the Clean Plugin assumes that these files are generated inside the target directory.
For what you describe, it is simpler to just prevent the maven-clean-plugin
from running during the clean
phase, and attach customPlugin to the clean
phase instead. This is simpler than short-circuiting the whole lifecycle, and keeps all your maven config in your pom.
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-customPlugin-plugin</artifactId>
<version>customPlugin-version</version>
<executions>
<execution>
<id>customised-clean</id>
<goals>
<goal>customClean</goal>
</goals>
<phase>clean</phase>
</execution>
</executions>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With