Apache Maven 3 Cookbook
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Extending <strong>Apache</strong> <strong>Maven</strong><br />
<br />
<br />
<br />
<br />
myProperties is now available for use in your MOJO and its values are read during<br />
execution from the POM file.<br />
For a plugin that needs to be executed from the console, a short command<br />
line is preferable. Here's a quick recap of how we executed the plugin from<br />
the command line:<br />
$ mvn net.srirangan.packt.maven:maven-plug101-plugin:1.0-<br />
SNAPSHOT:helloworld<br />
A little too long, don't you think? Remember how we ran the Jetty server through the<br />
plugin in earlier chapters?<br />
$ mvn jetty:run<br />
Short and sweet. How do we do the same, that is, shorten the command-line call with<br />
our plugin? (We're off to a good start, so the process of shortening won't be<br />
very hard.)<br />
<br />
<br />
<br />
Firstly, we have the latest version of the plugin installed in our local<br />
repository. That is what we're trying to execute. We can directly do<br />
away with the version number, and our command becomes:<br />
$ mvn net.srirangan.packt.maven:maven-plug101-<br />
plugin:helloworld<br />
We also followed the <strong>Maven</strong> plugin naming conventions, that is,<br />
maven-{plugin_name}-plugin. This allows us to shorten it a bit further.<br />
Finally, add the plugin's groupId as a pluginGroup in the <strong>Maven</strong> settings<br />
file (settings.xml):<br />
<br />
net.srirangan.packt.maven<br />
<br />
<br />
We should now be able to run the plugin using a short command in<br />
the console:<br />
$ mvn plug101:helloworld<br />
5. Here's how you integrate the <strong>Apache</strong> <strong>Maven</strong> plugin with the project build lifecycle:<br />
You will need to modify the project's POM file and include the executions element<br />
in the build and plugin description. The following code consists of the integration<br />
of the plugin with the compile phase:<br />
<br />
<br />
<br />
194