<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sonatype Blog &#187; plugin</title>
	<atom:link href="http://www.sonatype.com/people/tag/plugin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sonatype.com/people</link>
	<description>Sonatype is transforming software development with tools, information and services that enable organizations to build better software, faster, using open-source components.</description>
	<lastBuildDate>Wed, 23 May 2012 14:24:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Maven How-To: Merging Plugin Configuration in Complex Projects</title>
		<link>http://www.sonatype.com/people/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/</link>
		<comments>http://www.sonatype.com/people/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 15:00:02 +0000</pubDate>
		<dc:creator>bbentmann</dc:creator>
				<category><![CDATA[Maven]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[pom]]></category>

		<guid isPermaLink="false">http://www.sonatype.com/people/?p=6852</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/' addthis:title='Maven How-To: Merging Plugin Configuration in Complex Projects '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>In projects with many parent POMs, profiles, and plugin management sections, one can easily end up in a situation where the effective configuration for a plugin is the result of merging many configuration blocks from the various POM sources together. Not knowing the details of this merge process naturally leads to some confusion about why [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/' addthis:title='Maven How-To: Merging Plugin Configuration in Complex Projects '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div><p>In projects with many parent POMs, profiles, and plugin management sections, one can easily end up in a situation where the effective configuration for a plugin is the result of merging many configuration blocks from the various POM sources together.</p>

<p>Not knowing the details of this merge process naturally leads to some confusion about why an effective configuration looks the way it looks, or why changes to some parent POM&#8217;s configuration don&#8217;t have the desired effects in child POMs.</p>

<p>This post attempts to shed some light on this confusion, and provides you with a sense of how Maven merges plugin configuration from multiple sources.   This post uses attributes which are available in Maven 3.0.2.</p>

<p><span id="more-6852"></span></p>

<h2>The Simplest Case: Merging Parent and Child POMs</h2>

<p>As a concrete example, let&#8217;s assume we have a parent POM with the following plugin configuration:</p>

<p><script src="https://gist.github.com/777699.js?file=Plugin%20Configuration%20Example"></script> Let&#8217;s further assume we have a child POM that inherits from the above parent and that specifies the following configuration for the same plugin:  <script src="https://gist.github.com/777703.js?file=Plugin%20Configuration%20Example%20%232"></script></p>

<p>Now, as an invocation of <tt>mvn help:effective-pom</tt> will show you, the effective plugin configuration for the child project will be:</p>

<p><script src="https://gist.github.com/777706.js?file=plugin-config-merge.xml"></script> This result demonstrates the default merge behavior. The configuration elements are recursively merged based on the element name, and elements from the parent POM are only added to the result when the child POM does not contain an equally named element.  Let me stress that merging of plugin configuration is purely an operation on the XML DOM tree. In particular, the merge process has no knowledge of the actual data structures in the plugin that will be configured nor their semantics. In other words, configuration values are generally not considered as merge keys when combining child and parent elements, only the name of the configuration elements is used to identify conflicting elements that need to be merged.</p>

<h2>Controlling the Merge Process with combine.children and combine.self</h2>

<p>Sometimes the default merge behavior doesn&#8217;t produce the intended configuration. In this case, one can use two attributes on the child configuration to adjust the behavior as shown in the next child POM:
<script src="https://gist.github.com/777709.js?file=controlling-merge-with-hints.xml"></script></p>

<p>Assuming the above child POM still inherits from the previously sketched parent POM, one would now get the following effective configuration:</p>

<script src="https://gist.github.com/777710.js?file=merge-hints-results.xml"></script>

<p>As you can see here, usage of <tt>combine.children="append"</tt> results in the concatenation of parent and child elements, in that order. The attribute <tt>combine.self="override"</tt> on the other hand completely suppresses parent configuration to be inherited. That said, it&#8217;s senseless to specify both <tt>combine.self="override"</tt> and <tt>combine.children="append"</tt> for a configuration element, the former directive takes precedence.</p>

<p>Note that these attributes only apply to the configuration element they are declared on, and are not propagated to nested elements. That is if the <tt>&lt;item&gt;</tt> element from our last child POM would be a complex structure instead of a mere string, its sub elements would still be subject to the default merge strategy.</p>

<p>The <tt>combine.*</tt> attributes are however inherited along a hierarchy of POMs. So some care must be taken when adding those attributes to a configuration snippet in a parent POM as this might affect child or grand-child POMs unless those explicitly override the attributes themselves.</p>

<p>Last but not least, please note that the attributes described here to control merging only apply to plugin configuration. You cannot use these attributes on other elements of the POM.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sonatype.com/people/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieving a plugin&#039;s documentation</title>
		<link>http://www.sonatype.com/people/2010/12/retrieving-a-plugins-documentation/</link>
		<comments>http://www.sonatype.com/people/2010/12/retrieving-a-plugins-documentation/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 12:00:50 +0000</pubDate>
		<dc:creator>Anders Hammar</dc:creator>
				<category><![CDATA[Sonatype]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.sonatype.com/people/?p=6642</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2010/12/retrieving-a-plugins-documentation/' addthis:title='Retrieving a plugin&#039;s documentation '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>One of the key things driving the adoption of Maven, is the rich set of plugins available. Whenever you want to add some functionality to the build process, or possibly even just want to do a one-time job, chances are that there is already a plugin for that. When you want to use Maven plugins, you [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2010/12/retrieving-a-plugins-documentation/' addthis:title='Retrieving a plugin&#039;s documentation '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div><p>One of the key things driving the adoption of Maven, is the rich set  of plugins available. Whenever you want to add some functionality to the  build process, or possibly even just want to do a one-time job, chances  are that there is already a plugin for that.</p>

<p>When you want to use Maven  plugins, you need to get more information about them to know how to use  them. Most often, there is online documentation that describes the  goals and parameters. However, sometimes no such documentation exists or  you just cannot find it. Also, the online documentation very often  describes the latest version of the plugin &#8211; but what if you have to use an  older version?</p>

<p>This  blog post will explain the different options you have to retrieve  information about a plugin, just by using Maven itself.</p>

<p><span id="more-6642"></span></p>

<p>As mentioned above, the simplest way of viewing a plugin&#8217;s  documentation is to use the one provided online. Not only does this documentation describe the  available goals and the plugin&#8217;s parameters, but it most often also provides  examples and other useful information. If available, this should  normally be your first choice. However, there are at least two other  ways of retrieving information from a plugin about it&#8217;s goals and  parameters. These come in handy when there is no other documentation, and also when you want to be sure to find the goals and parameters of a  specific version of the plugin.</p>

<p>The first option, and most likely the easiest one to remember, is to use the <tt>help</tt> goal of the plugin itself. Here&#8217;s an example:</p>

<blockquote>
<pre>mvn compiler:help</pre>
</blockquote>

<p>This would give you an overview of the goals of the Maven Compiler Plugin. If you want more information, add the <tt>detail</tt> parameter:</p>

<blockquote>
<pre>mvn compiler:help -Ddetail</pre>
</blockquote>

<p>If you want to focus on a specific goal, you do that through the <tt>goal</tt> parameter:</p>

<pre>
<blockquote>mvn compiler:help -Ddetail -Dgoal=compile</blockquote>
</pre>

<p>Please note that this will describe the version of the plugin according  to normal Maven plugin management. To override that, there is always the  option of specify the plugin version through the standard Maven syntax.</p>

<blockquote>
<pre>mvn org.apache.maven.plugins:maven-compiler-plugin:2.3:help -Ddetail -Dgoal=compile</pre>
</blockquote>

<p><a rel="attachment wp-att-6652" href="http://www.sonatype.com/people/2010/12/retrieving-a-plugins-documentation/blog150-help_goal-2/"><img class="alignleft size-full wp-image-6652" title="blog150-help_goal" src="http://www.sonatype.com/people/wp-content/uploads/2010/12/blog150-help_goal.png" alt="" width="797" height="606" /></a></p>

<p>Another great thing about the help goal is that it is created by Maven Plugin Plugin. So you could very easy add this feature to your own plugin as well, only by adding a <a href="http://maven.apache.org/plugins/maven-plugin-plugin/examples/generate-help.html" target="_blank">simple POM configuration</a>. However, this dependency is also the drawback. The functionality in Maven Plugin Plugin was added in version 2.4, so plugins (or older versions of plugins) written before that would not have the help goal. Fortunately, there is another option for those cases.</p>

<p>A fallback option is to use the Maven Help Plugin and its describe goal. It will work with any version of a plugin you want to describe. As an example, here is the equivalent to the one above:</p>

<pre>
<blockquote>mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin:2.3 -Ddetail -Dmojo=compile</blockquote>
</pre>

<p><a rel="attachment wp-att-6661" href="http://www.sonatype.com/people/2010/12/retrieving-a-plugins-documentation/blog150-describe_goal-2/"><img class="alignleft size-full wp-image-6661" title="blog150-describe_goal" src="http://www.sonatype.com/people/wp-content/uploads/2010/12/blog150-describe_goal.png" alt="" width="797" height="606" /></a></p>

<p>As this feature is described in detail in <a href="http://www.sonatype.com/books/mvnref-book/reference/installation-sect-help-plugin-install.html#installation-sect-describing-plugin" target="_blank">chapter 6.3.1 of Maven: The Complete Reference</a> and also in the online documentation of <a href="http://maven.apache.org/plugins/maven-help-plugin/examples/describe-configuration.html" target="_blank">Maven Help Plugin</a>, I will not go into more details about it.</p>

<p>Try the different options and see which one you prefer. Please note that even if they provide much of the same information there are some slight differences. In some areas, like information about default phase binding, I find the help:describe option more informative.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sonatype.com/people/2010/12/retrieving-a-plugins-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DIY: Retrieving a Maven plugin&#039;s documentation</title>
		<link>http://www.sonatype.com/people/2010/06/diy-retrieving-a-maven-plugins-documentation/</link>
		<comments>http://www.sonatype.com/people/2010/06/diy-retrieving-a-maven-plugins-documentation/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 13:00:20 +0000</pubDate>
		<dc:creator>Anders Hammar</dc:creator>
				<category><![CDATA[Maven]]></category>
		<category><![CDATA[Sonatype]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.sonatype.com/people/?p=5551</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2010/06/diy-retrieving-a-maven-plugins-documentation/' addthis:title='DIY: Retrieving a Maven plugin&#039;s documentation '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>One of the key things driving the adoption of Maven, is the rich set of plugins available. Whenever you want to add some functionality to the build process, or possibly even just want to do a one-time job, chances are that there is already a plugin for that. When you want to use Maven plugins, [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2010/06/diy-retrieving-a-maven-plugins-documentation/' addthis:title='DIY: Retrieving a Maven plugin&#039;s documentation '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div><p>One of the key things driving the adoption of Maven, is the rich set of plugins available. Whenever you want to add some functionality to the build process, or possibly even just want to do a one-time job, chances are that there is already a plugin for that.</p>

<p>When you want to use Maven plugins, you need to get more information about them to know how to use them. Most often, there is on-line documentation that describes the goals and parameters. However, sometimes no such documentation exists or you just cannot find it. Also, the on-line documentation very often describes the latest version of the plugin &#8211; what if you have to use an older version?</p>

<p>I recently faced a closed-source plugin, with no documentation. This blog post will explain the different options you have to retrieve information about a plugin, just by using Maven itself.</p>

<p>As mentioned above, the simplest way of viewing a plugin&#8217;s documentation is to use the one provided on-line. Normally in HTML and created by the Maven Site Plugin, this is what we have got used to with most open source plugins.</p>

<p>Not only does this documentation describe the available goals and its parameters, but it most often also provides examples and other useful information. If available, this should normally be your first choice. However, there are at least two other ways of retrieving information from a plugin about it&#8217;s goals and parameters. These come in handy when there is no other documentation, but also when you want to be sure to find the goals and parameters of a specific version of the plugin.</p>

<p><span id="more-5551"></span></p>

<p>The first option, and most likely the easiest one to remember, is to use the help goal of the plugin itself. Here&#8217;s an example:</p>

<p><strong>mvn compiler:help</strong></p>

<p>This would give you an overview of the goals of the Maven Compiler Plugin. If you want more information, add the <strong>detail</strong> parameter:</p>

<p><strong>mvn compiler:help –Ddetail</strong></p>

<p>If you want to focus on a specific goal, you do that through the goal parameter:</p>

<p><strong>mvn compiler:help –Ddetail –Dgoal=compile</strong></p>

<p>Please note that this will describe the version of the plugin according to normal Maven plugin management. To override that, there is always the option of specify the plugin version through the standard Maven syntax.</p>

<p><strong>mvn org.apache.maven.plugins:maven-compiler-plugin:2.3:help -Ddetail -Dgoal=compile</strong></p>

<p><a href="http://www.sonatype.com/people/wp-content/uploads/2010/06/blog150-help_goal.jpg"><img class="alignnone size-full wp-image-5576" title="blog150-help_goal" src="http://www.sonatype.com/people/wp-content/uploads/2010/06/blog150-help_goal.jpg" alt="" width="717" height="545" /></a></p>

<p>Another great thing about the help goal is that it is created by Maven Plugin Plugin. So you could very easy add this feature to your own plugin as well, only by adding a <a href="http://maven.apache.org/plugins/maven-plugin-plugin/examples/generate-help.html" target="_blank">simple POM configuration</a>.</p>

<p>However, this dependency is also the drawback. The functionality in Maven Plugin Plugin was added in version 2.4, so plugins (or older versions of plugins) written before that would not have the <strong>help</strong> goal. Fortunately, there is another option for those cases.</p>

<p>A fallback option is to use the Maven Help Plugin and its describe goal. It will work with any version of a plugin you want to describe. As an example, here is the equivalent to the one above:</p>

<p><strong>mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin:2.3 -Ddetail -Dmojo=compile</strong></p>

<p><strong> </strong></p>

<p><a href="http://www.sonatype.com/people/wp-content/uploads/2010/06/blog150-describe_goal.jpg"><img class="alignnone size-full wp-image-5577" title="blog150-describe_goal" src="http://www.sonatype.com/people/wp-content/uploads/2010/06/blog150-describe_goal.jpg" alt="" width="717" height="545" /></a></p>

<p>As this feature is described in detail in chapter 6.3.1 of Maven: The Complete Reference and also in the on-line documentation of <a href="http://maven.apache.org/plugins/maven-help-plugin/examples/describe-configuration.html" target="_blank">Maven Help Plugin</a>, I will not go into more details about it.</p>

<p>Try the different options and see which one you prefer. Please do note that even if they provide much the same info, there are some slight differences. In some areas, like information about default phase binding, I find the <strong>help:describe</strong> option more informative.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sonatype.com/people/2010/06/diy-retrieving-a-maven-plugins-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to make an executable jar in Maven</title>
		<link>http://www.sonatype.com/people/2009/08/how-to-make-an-executable-jar-in-maven/</link>
		<comments>http://www.sonatype.com/people/2009/08/how-to-make-an-executable-jar-in-maven/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 17:13:18 +0000</pubDate>
		<dc:creator>Brian Fox</dc:creator>
				<category><![CDATA[Sonatype]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Nexus]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://www.sonatype.com/people/?p=2696</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2009/08/how-to-make-an-executable-jar-in-maven/' addthis:title='How to make an executable jar in Maven '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>It&#8217;s been a while since I posted, so here&#8217;s a quick and dirty code by example: If you want to make a standalone jar (ie one with no dependencies) executable, here&#8217;s how you do it: &#60;pluginManagement&#62; &#60;plugins&#62; &#60;plugin&#62; &#60;groupId&#62;org.apache.maven.plugins&#60;/groupId&#62; &#60;artifactId&#62;maven-jar-plugin&#60;/artifactId&#62; &#60;configuration&#62; &#60;archive&#62; &#60;manifest&#62; &#60;addClasspath&#62;true&#60;/addClasspath&#62; &#60;mainClass&#62;com.yourcompany.YourClass&#60;/mainClass&#62; &#60;/manifest&#62; &#60;/archive&#62; &#60;/configuration&#62; &#60;/plugin&#62; &#60;/plugins&#62; &#60;/pluginManagement&#62; If however you have [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2009/08/how-to-make-an-executable-jar-in-maven/' addthis:title='How to make an executable jar in Maven '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div><p>It&#8217;s been a while since I posted, so here&#8217;s a quick and dirty code by example:</p>

<p>If you want to make a standalone jar (ie one with no dependencies) executable, here&#8217;s how you do it:
<span id="more-2696"></span></p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pluginManagement<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.maven.plugins<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-jar-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;archive<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;manifest<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;addClasspath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/addClasspath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mainClass<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.yourcompany.YourClass<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mainClass<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/manifest<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/archive<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pluginManagement<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<p>If however you have dependencies, you will probably want to bundle them into a single jar, otherwise making it executable is not very helpful. You can use the assembly plugin to do it like this:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.maven.plugins<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-assembly-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>attached<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>package<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;descriptorRefs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
             <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;descriptorRef<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jar-with-dependencies<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/descriptorRef<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/descriptorRefs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;archive<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;manifest<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mainClass<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.yourcompany.YourClass<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mainClass<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/manifest<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/archive<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<p>A few comments:</p>

<ol>
    <li>I didn&#8217;t specify plugin versions in the example. You should always specify a plugin version, but you should do it in the pluginManagement section instead. See this <a href="http://www.sonatype.com/people/2008/04/maven-209-released/">post</a> for how and why. </li>
    <li>Notice the assembly plugin configuration has an execution, while the jar plugin does not. This is because the jar plugin will run automatically based on the packaging, which is assumed to be &#8220;jar&#8221; in this example. The assembly plugin needs an execution to &#8220;bind&#8221; it to the lifecycle and here we tell it which goal to run and which phase to run in.</li>
    <li>Notice also that the jar plugin is configured in pluginManagement. This is my personal best practice and I explain why <a href="http://www.sonatype.com/people/2008/05/optimal-maven-plugin-configuration/">here</a>.</li>
</ol>

<p>See more Maven How-Tos and Best Practices <a href="http://www.sonatype.com/people/2009/04/summary-of-maven-how-tos/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sonatype.com/people/2009/08/how-to-make-an-executable-jar-in-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to make a plugin that runs once during a build</title>
		<link>http://www.sonatype.com/people/2009/05/how-to-make-a-plugin-run-once-during-a-build/</link>
		<comments>http://www.sonatype.com/people/2009/05/how-to-make-a-plugin-run-once-during-a-build/#comments</comments>
		<pubDate>Fri, 22 May 2009 11:36:05 +0000</pubDate>
		<dc:creator>Brian Fox</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://www.sonatype.com/people/?p=2270</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2009/05/how-to-make-a-plugin-run-once-during-a-build/' addthis:title='How to make a plugin that runs once during a build '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>With it's default behavior, Maven runs a plugin invocation for each project in a multi-module build. For plugins that operate on a single project at a time, this is what the author wants.

Some plugins are what we call "aggregators" which means they actually do want all the information about the full multi-module build before execution. These plugins, when run on a tree of projects cause Maven to resolve all the children before calling the plugin's execute() method. In this mode a plugin executes just once, but effectively on the whole tree at once. (<em>as a side note, you never want to bind an aggregator goal in your pom as this would cause the plugin to run an n! recursive build since the lifecycle would step into each child and execute the aggregator...which would cause Maven to reresolve all the children, etc</em>)

Sometimes neither of those behaviors are what you want.]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2009/05/how-to-make-a-plugin-run-once-during-a-build/' addthis:title='How to make a plugin that runs once during a build '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div><p>With it&#8217;s default behavior, Maven runs a plugin invocation for each project in a multi-module build. For plugins that operate on a single project at a time, this is what the author wants.</p>

<p>Some plugins are what we call &#8220;aggregators&#8221; which means they actually do want all the information about the full multi-module build before execution. These plugins, when run on a tree of projects cause Maven to resolve all the children before calling the plugin&#8217;s execute() method. In this mode a plugin executes just once, but effectively on the whole tree at once. (<em>as a side note, you never want to bind an aggregator goal in your pom as this would cause the plugin to run an n! recursive build since the lifecycle would step into each child and execute the aggregator&#8230;which would cause Maven to reresolve all the children, etc</em>)</p>

<p><span id="more-2270"></span></p>

<p>Sometimes neither of those behaviors are what you want. If I want a plugin to run only once in my build, I can do that by only binding it once in a pom. But what if you want it to run once regardless of if I start my build at the root, or somewhere down in a module? An example of where this is handy is the <a href="http://maven.apache.org/plugins/maven-enforcer-plugin/">maven-enforcer-plugin</a>&#8230; if you&#8217;re checking environmental constraints like jdk, os, maven version, it&#8217;s pretty much guaranteed that this can&#8217;t change between the root and when the next module is built.</p>

<p>This has most recently cropped up as a use case in the <a href="http://maven.apache.org/plugins/maven-assembly-plugin/">maven-assembly-plugin</a>. We want to configure the plugin to produce a source archive during releases of the entire tree. Since the root project would contain the code below that point, we don&#8217;t need to also archive the source for each sub-module separately. We want to be able to configure this at our &#8220;Maven&#8221; or &#8220;Apache&#8221; pom (the moral equivalent of a &#8220;<a href="http://www.sonatype.com/people/2008/05/misused-maven-terms-defined/">Corporate</a>&#8221; pom) and have it simply work regardless of where a build is launched from.</p>

<p>It turns out that it is fairly easy for a plugin to programatically detect when it is building the project at the execution root (that is where mvn was launched). The code looks like this:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>57
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">        <span style="color: #000066; font-weight: bold;">boolean</span> result <span style="color: #339933;">=</span> mavenSession.<span style="color: #006633;">getExecutionRootDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equalsIgnoreCase</span><span style="color: #009900;">&#40;</span>basedir.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>A full mojo to implement this would look like this:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @goal skipper
* @execute phase=&quot;validate&quot;
**/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SkipperMojo <span style="color: #000000; font-weight: bold;">extends</span> AbstractMojo
<span style="color: #009900;">&#123;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Base directory of the project.
     *
     * @parameter default-value=&quot;${basedir}&quot;
     * @required
     * @readonly
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">File</span> basedir<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * This will cause the assembly to run only at the top of a given module tree. That is, run in the project
     * contained in the same folder where the mvn execution was launched.
     * @parameter expression=&quot;${runOnlyAtExecutionRoot}&quot; default-value=&quot;false&quot;
     * @since 2.2-beta-4
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> runOnlyAtExecutionRoot<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">throws</span> MojoExecutionException, MojoFailureException
    <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//run only at the execution root.</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>runOnlyAtExecutionRoot <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>isThisTheExecutionRoot<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            getLog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Skipping the assembly in this project because it's not the Execution Root&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #009900;">&#123;</span>
            getLog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Doing something usefull&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Returns true if the current project is located at the Execution Root Directory (where mvn was launched)
     * @return
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">boolean</span> isThisTheExecutionRoot<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        Log log <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getLog</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        log.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Root Folder:&quot;</span> <span style="color: #339933;">+</span> mavenSession.<span style="color: #006633;">getExecutionRootDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        log.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Current Folder:&quot;</span><span style="color: #339933;">+</span> basedir <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> result <span style="color: #339933;">=</span> mavenSession.<span style="color: #006633;">getExecutionRootDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equalsIgnoreCase</span><span style="color: #009900;">&#40;</span>basedir.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            log.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;This is the execution root.&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #009900;">&#123;</span>
            log.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;This is NOT the execution root.&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.sonatype.com/people/2009/05/how-to-make-a-plugin-run-once-during-a-build/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the Project Assembly: To Create Example Projects</title>
		<link>http://www.sonatype.com/people/2008/11/using-the-project-assembly-to-create-example-projects/</link>
		<comments>http://www.sonatype.com/people/2008/11/using-the-project-assembly-to-create-example-projects/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 15:02:31 +0000</pubDate>
		<dc:creator>Tim O'Brien</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://blogs.sonatype.com/people/book/?p=192</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2008/11/using-the-project-assembly-to-create-example-projects/' addthis:title='Using the Project Assembly: To Create Example Projects '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>Anders Nawroth of the Neo4J project asked an interesting question on the neo4j-user list: What&#8217;s the best option when deploying neo4j code examples using Maven? It&#8217;s really not of any interest to deploy the artifact itself, it&#8217;s the sources (if possible with some exclusion of resources) that we want. Anders&#8217; requirements: create a project which [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2008/11/using-the-project-assembly-to-create-example-projects/' addthis:title='Using the Project Assembly: To Create Example Projects '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div><p><a href="http://explore.twitter.com/nawroth">Anders Nawroth</a> of the <a href="http://neo4j.org/">Neo4J</a> project asked an interesting question on the <a href="http://lists.neo4j.org/pipermail/user/2008-November/000879.html">neo4j-user</a> lis<a href="http://cms.sonatype.com/wordpress/wp-content/uploads/2008/11/assembly-plugin.png"><img class="alignright size-thumbnail wp-image-200" src="http://cms.sonatype.com/wordpress/wp-content/uploads/2008/11/assembly-plugin.png" alt="" width="102" height="72" /></a>t:</p>

<blockquote><strong>What&#8217;s the best option when deploying neo4j code examples
using Maven?</strong> It&#8217;s really not of any interest to deploy the artifact
itself, it&#8217;s the sources (if possible with some exclusion of resources)
that we want.</blockquote>

<p><em>Anders&#8217; requirements:</em> create a project which packages itself, wire the appropriate goal into the lifecycle.   He&#8217;s headed in the right direction, the Maven Assembly Plugin, but he might not know about the pre-defined assembly descriptors as they are somewhat <a href="http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#project">hidden</a> on the Apache Maven site.    Since other projects might have similar requirements, here&#8217;s a quick explanation of all the moving parts&#8230;</p>

<h2><span id="more-240"></span>What is the Maven Assembly Plugin?</h2>

<p>The Maven Assembly Plugin allows you to create an archive with an arbitrary structure.   If you have a project which needs to produce a ZIP file with a <em>bin/</em> directory an a set of shell scripts, or if you want to create an archive which contains a particular project&#8217;s bytecode and all the runtime dependencies, Maven Assembly Plugin is the place to look.   To generate an archive, you&#8217;ll need to do a few things:</p>

<ul>
    <li>Include the Maven Assembly Plugin in your project&#8217;s <em>pom.xml </em>file.</li>
    <li>Configure an assembly by referencing a built-in assembly or define your own assembly.</li>
    <li>(optional) configure the lifecycle to bind the assembly goal to the package phase of the lifecycle.</li>
</ul>

<h2>What is an Assembly?</h2>

<p>The Maven Assembly Plugin produces an assembly of files and folders using an Assembly descriptor which describes the contents of a directory.   You can use one of several predefined assembly descriptors which are built into the Maven Assembly plugin, or you can define your own assembly by configuring your assembly in an assembly descriptor.   An assembly descriptor is an XML file which selects files and directories to include in the final, assembled artifact.</p>

<p><a href="http://cms.sonatype.com/wordpress/wp-content/uploads/2008/11/assembly-graphic1.png"><img class="aligncenter size-full wp-image-197" src="http://cms.sonatype.com/wordpress/wp-content/uploads/2008/11/assembly-graphic1.png" alt="" width="500" height="208" /></a></p>

<p>Just what sort of &#8220;assemblies&#8221; can you create on your own with an Assembly descriptor?   Just about anything, a collection of .class files and all of your runtime dependency JARs?  Sure.  The assembly descriptor is flexible enough to describe just about anything.   If you want a full explanation of the power of Maven Assemblies, read the <a href="http://www.sonatype.com/book/reference/assemblies.html">Assemblies Chapter of the Free Maven Book</a> or <a href="http://www.sonatype.com/book/reference/customizing.html#section-custom-packaged">Chapter 4</a> which introduces a built-in assembly descriptor.</p>

<h2>A Project Which Assembles Itself</h2>

<p>Back to Anders&#8217; requirements, he wants a project that can package itself up as an example project.    He also wants this assembly to be created when he runs mvn deploy.  To do this, he can use the built-in project descriptor.   Adding the following plugin configuration to any project will configure this built-in project descriptor to create an assembly of a project itself (a self-replicating project) and the executions section will attach the &#8220;assembly:attached&#8221; goal to the package phase of the lifecycle.</p>

<pre>  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
        &lt;configuration&gt;
          &lt;descriptorRefs&gt;
            &lt;descriptorRef&gt;project&lt;/descriptorRef&gt;
          &lt;/descriptorRefs&gt;
        &lt;/configuration&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;id&gt;examples&lt;/id&gt;
            &lt;phase&gt;package&lt;/phase&gt;
            &lt;goals&gt;
              &lt;goal&gt;attached&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;</pre>

<p>Go ahead, try it.  Run mvn package or mvn deploy and you&#8217;ll end up with an assembly in ${basedir}/target.   If you want to customize the name of the final product, use the finalName element in the build section of your POM.</p>

<h2>The Lifecycle</h2>

<p>My next post will likely be on the lifecycle, I&#8217;ve had a few questions from people over the past few weeks about running specific goals directly from the command-line.  It appears that many people haven&#8217;t fully grok&#8217;d the Maven Lifecycle.  Many people grew familiar with Maven 1, the way that people customized a build in Maven 1 was to string along a number of goals.   If you needed to run a specific goal, you would just craft a long command line.   In Maven 2, you should shy away from running specific goals on the command line, and you should configure executions (see above).   This is the more natural way to customize a build, think of it as hooking your own project&#8217;s customized goals to the default lifecycle.   If you find yourself running &#8220;mvn deploy assembly:assembly&#8221; often, you should take a look at the executions element in your plugin configuration.</p>

<p>For more information about the Maven 2 Lifecycle, read <a href="http://www.sonatype.com/book/reference/lifecycle.html">Chapter 10: Lifecycles</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sonatype.com/people/2008/11/using-the-project-assembly-to-create-example-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimal Maven Plugin configuration</title>
		<link>http://www.sonatype.com/people/2008/05/optimal-maven-plugin-configuration/</link>
		<comments>http://www.sonatype.com/people/2008/05/optimal-maven-plugin-configuration/#comments</comments>
		<pubDate>Tue, 27 May 2008 01:57:29 +0000</pubDate>
		<dc:creator>Brian Fox</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://blogs.sonatype.com/people/brian/?p=84</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2008/05/optimal-maven-plugin-configuration/' addthis:title='Optimal Maven Plugin configuration '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>Maven has two sections in the pom relating to plugin configuration: project.build.plugins and project.build.pluginManagment.plugins. These two sections are unfortunately often confused and misused. PluginManagement is similar to dependencyManagment in that it provides configuration and defaults for plugins if they are used in the build. This is where we recommend you lock down your plugin versions, [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2008/05/optimal-maven-plugin-configuration/' addthis:title='Optimal Maven Plugin configuration '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Maven has two sections in the pom relating to plugin configuration: <a href="http://maven.apache.org/pom.html#Plugins" target="_blank">project.build.plugins</a> and <a href="http://maven.apache.org/pom.html#Plugin_Management" target="_blank">project.build.pluginManagment.plugins</a>. These two sections are unfortunately often confused and misused.
<span id="more-616"></span>
PluginManagement is similar to <a href="http://maven.apache.org/pom.html#Dependency_Management" target="_blank">dependencyManagment </a>in that it provides configuration and defaults for plugins <em>if they are used in the build</em>. This is where we recommend you <a href="http://blogs.sonatype.com/brian/2008/04/10/1207873624557.html" target="_blank">lock down your plugin versions</a>, but it also allows default configuration.</p>

<p>The regular plugins section also allows the version and default configuration to be defined, and this is where the confusion lies. It is technically valid to define the plugin version and default configuration here, but I find it easier to grok the pom when following this guideline:</p>

<ul>
    <li>If the plugin block is not defining an execution (and thus binding maven to do something in the lifecycle), put that block in pluginManagment</li>
</ul>

<p>This means that configuration for plugins brought in by the default lifecycle such as resources, compiler, jar, etc will almost always go in the pluginManagement section. Doing so tends to keep your regular plugins section rather small and only showing the config for plugins that are doing <em>additional</em> things during the lifecycle.</p>

<p>Following the above defined guideline will also have you locating the config for plugins that are primarily run from the command line in pluginManagment&#8230;again keeping the plugins section clean and concise.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sonatype.com/people/2008/05/optimal-maven-plugin-configuration/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>How to override a plugin&#039;s dependency in Maven</title>
		<link>http://www.sonatype.com/people/2008/04/how-to-override-a-plugins-dependency-in-maven/</link>
		<comments>http://www.sonatype.com/people/2008/04/how-to-override-a-plugins-dependency-in-maven/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 14:53:00 +0000</pubDate>
		<dc:creator>Brian Fox</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[checkstyle]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://blogs.sonatype.com/people/brian/?p=72</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2008/04/how-to-override-a-plugins-dependency-in-maven/' addthis:title='How to override a plugin&#039;s dependency in Maven '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>Maven 2.0.9 introduced the ability to override a dependency used by a plugin. This is handy when you want to use a newer checkstyle, pmd, etc jar than is included by default in the plugin. How you go about doing this actually depends on your use case because of an oversight in the Maven 4.0.0 [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2008/04/how-to-override-a-plugins-dependency-in-maven/' addthis:title='How to override a plugin&#039;s dependency in Maven '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Maven 2.0.9 introduced the ability to override a dependency used by a plugin. This is handy when you want to use a newer checkstyle, pmd, etc jar than is included by default in the plugin.</p>

<p>How you go about doing this actually depends on your use case because of an oversight in the Maven 4.0.0 model used by the Maven 2.0.x versions.</p>

<p>If you are using a plugin as a normal build plugin (as opposed to a report) then you will have it bound similar to this:
<span id="more-609"></span></p>

<pre>&lt;plugin&gt;
  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  &lt;artifactId&gt;maven-checkstyle-plugin&lt;/artifactId&gt;
  &lt;version&gt;2.1&lt;/version&gt;
  &lt;executions&gt;
      &lt;execution&gt;
        &lt;id&gt;check my sources&lt;/id&gt;
        &lt;goals&gt;
          &lt;goal&gt;check&lt;/goal&gt;
        &lt;/goals&gt;
        &lt;phase&gt;compile&lt;/phase&gt;
      &lt;/execution&gt;
  &lt;/executions&gt;
&lt;/plugin&gt;</pre>

<p>This version of the <code>maven-checkstyle-plugin</code> will use checkstyle 4.1 by default. If I wanted to use version 4.4 instead, I simply add a dependency block inside my plugin block like this:</p>

<pre>&lt;plugin&gt;
  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  &lt;artifactId&gt;maven-checkstyle-plugin&lt;/artifactId&gt;
  &lt;version&gt;2.1&lt;/version&gt;
  &lt;executions&gt;
      &lt;execution&gt;
        &lt;id&gt;check my sources&lt;/id&gt;
        &lt;goals&gt;
          &lt;goal&gt;check&lt;/goal&gt;
        &lt;/goals&gt;
        &lt;phase&gt;compile&lt;/phase&gt;
      &lt;/execution&gt;
  &lt;/executions&gt;
<span style="color: red;">  &lt;dependencies&gt;
     &lt;dependency&gt;
        &lt;groupId&gt;checkstyle&lt;/groupId&gt;
        &lt;artifactId&gt;checkstyle&lt;/artifactId&gt;
        &lt;version&gt;4.4&lt;/version&gt;
     &lt;/dependency&gt;
  &lt;/dependencies&gt;</span>
&lt;/plugin&gt;</pre>

<p>That was easy, right? As long as the new version you have introduced is api compatible with the version the plugin was linked against, you should be good.</p>

<p>Now, what about reports? Well unfortunately, the Model used in 2.0.x doesn&#8217;t allow dependencies to be specified inside the reporting block (<a href="http://jira.codehaus.org/browse/MNG-1948">MNG-1948</a>)</p>

<p>In the process of creating the samples for this how-to, I discovered that the extensions don&#8217;t override the reporting plugin dependencies, so unfortunately there isn&#8217;t a way to override them. Stay tuned as we investigate how to deal with this.</p>

<p><strong>Update:</strong> There is a way to make this happen with reports. In the example below, I removed the execution from the plugin block and added the plugin as a report. It seems that the dependency is inherited when the plugin is used in reporting. Not quite obvious, but here&#8217;s what it looks like:</p>

<pre>&lt;build&gt;
   &lt;plugins&gt;
      &lt;plugin&gt;
         &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
         &lt;artifactId&gt;maven-checkstyle-plugin&lt;/artifactId&gt;
         &lt;version&gt;2.1&lt;/version&gt;
         &lt;dependencies&gt;
            &lt;dependency&gt;
               &lt;groupId&gt;checkstyle&lt;/groupId&gt;
               &lt;artifactId&gt;checkstyle&lt;/artifactId&gt;
               &lt;version&gt;4.4&lt;/version&gt;
            &lt;/dependency&gt;
         &lt;/dependencies&gt;
      &lt;/plugin&gt;
   &lt;/plugins&gt;
&lt;/build&gt;
&lt;reporting&gt;
   &lt;plugins&gt;
      &lt;plugin&gt;
         &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
         &lt;artifactId&gt;maven-checkstyle-plugin&lt;/artifactId&gt;
         &lt;version&gt;2.1&lt;/version&gt;
      &lt;/plugin&gt;
   &lt;/plugins&gt;
&lt;/reporting&gt;</pre>

<p>Checkstyle makes it easy to test this behavior because it writes out the checkstyle version in the results:</p>

<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;checkstyle version="4.4"&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sonatype.com/people/2008/04/how-to-override-a-plugins-dependency-in-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maven 2.0.9 Released and information about plugin versions.</title>
		<link>http://www.sonatype.com/people/2008/04/maven-209-released/</link>
		<comments>http://www.sonatype.com/people/2008/04/maven-209-released/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 23:27:04 +0000</pubDate>
		<dc:creator>Brian Fox</dc:creator>
				<category><![CDATA[Maven]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://blogs.sonatype.com/people/brian/?p=68</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2008/04/maven-209-released/' addthis:title='Maven 2.0.9 Released and information about plugin versions. '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>Maven 2.0.9 was released today. I previously blogged about the changes to the process that will hopefully lead to more stable releases in the future. Today I want to talk about some important changes in the release itself that improve the user experience a bit. Probably the biggest and most anticipated change is the shift [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.sonatype.com/people/2008/04/maven-209-released/' addthis:title='Maven 2.0.9 Released and information about plugin versions. '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div><p><a href="http://maven.apache.org/release-notes.html">Maven 2.0.9</a> was released today. I previously blogged about the changes to the process that will hopefully lead to more stable releases in the future. Today I want to talk about some important changes in the release itself that improve the user experience a bit.</p>

<p>Probably the biggest and most anticipated change is the shift towards specifying default versions for the core set of plugins. Before I go further, lets have a background lesson on how Maven handles the plugins and why this was a pain point for some users.
<span id="more-607"></span>
Unlike dependencies, Maven does not require a version of plugins to be specified. Ostensibly, this is because many plugins are introduced to the build lifecycle via one of the supported packaging types (jar,war,ear,etc). It&#8217;s not immediately obvious to a user exactly which plugins will be used and which versions they want to use. Requiring a version declaration in the pom for all plugins would immediately fail even the simplest of poms and is definately not newbie friendly.</p>

<p>If Maven encounters a plugin with no version declaration, regardless if introduced by the user or the packaging type, it will query the repository metadata to find the LATEST version.  LATEST and RELEASE are keywords that have special meaning but are recorded in the maven.metadata.xml. The maven-dependency-plugin&#8217;s metdata is shown below:</p>

<pre> &lt;metadata&gt;
    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
    &lt;version&gt;2.0-alpha-1-SNAPSHOT&lt;/version&gt;
    &lt;versioning&gt;
      <span style="color: red;">&lt;latest&gt;2.1-SNAPSHOT&lt;/latest&gt;
      &lt;release&gt;2.0&lt;/release&gt;</span>
      &lt;versions&gt;
        &lt;version&gt;2.0-alpha-1-SNAPSHOT&lt;/version&gt;
        &lt;version&gt;2.0-alpha-2-SNAPSHOT&lt;/version&gt;
        &lt;version&gt;2.0-alpha-3-SNAPSHOT&lt;/version&gt;
        &lt;version&gt;2.0-alpha-4-SNAPSHOT&lt;/version&gt;
        &lt;version&gt;2.0-alpha-5-SNAPSHOT&lt;/version&gt;
        &lt;version&gt;2.0-SNAPSHOT&lt;/version&gt;
        &lt;version&gt;2.0-alpha-1&lt;/version&gt;
        &lt;version&gt;2.0-alpha-2&lt;/version&gt;
        &lt;version&gt;2.0-alpha-3&lt;/version&gt;
        &lt;version&gt;2.0-alpha-4&lt;/version&gt;
        &lt;version&gt;2.0&lt;/version&gt;
        &lt;version&gt;2.1-SNAPSHOT&lt;/version&gt;
      &lt;/versions&gt;
      &lt;lastUpdated&gt;20080302232758&lt;/lastUpdated&gt;
    &lt;/versioning&gt;
  &lt;/metadata&gt;</pre>

<p>Note that this metadata is actually the metadata merged by Nexus from both the release and snapshots repositories that house the dependency plugin. Notice that LATEST is 2.1-SNAPSHOT, while RELEASE is 2.0. This is one reason why we recommend not combining snapshots and releases in the same repository. It is also why if you are add the apache or codehaus snapshot repositories to your settings you can get some odd behavior.</p>

<p>Every time a new release is pushed out, this metadata gets updated. Maven by default won&#8217;t look for a new LATEST if you already have a version of the plugin in your repository. That means a few things. First, it means that if we release a plugin you might not immediately pull it down. Second, it means that new members of your team are more likely to get new versions of the plugin than older ones&#8230;creating team platform inconsistencies. It is also why we sometimes tell you to try -U to look for new plugins.</p>

<p><em>So how do I avoid being subject to new plugin releases at inopportune times or having inconsistent results across a team?</em></p>

<p>It&#8217;s pretty easy actually: specify a version in your pom. If you have a large project or group of projects, this is not very scalable. The way to handle this is parallel to dependencies: define the version in build.pluginManagment and then omit the version in the build.plugins section.</p>

<p>During our <a href="http://www.sonatype.com/training/">Maven training classes</a>, we recommend creating a single corporate pom from which all your projects inherit. You may have individual business unit poms and team poms, but the point is you inherit up to a central pom where you can control certain things, particularly plugin versions.</p>

<p><em>Ok, now I know how to control my plugin versions, how do I know which versions I want? </em></p>

<p>Good question and there isn&#8217;t a great answer right now. The best way would be to use the new enforcer plugin to require all plugins are locked down. If it finds a plugin in use that isn&#8217;t locked down, it will tell you and it will tell you which plugin you are currently using. Unfortunately this is only available in the latest snapshot&#8230;but I promise to get it released shortly.</p>

<p>In the  meantime, the best way to go is to look in your local repository at org.apache.maven.plugins and org.codehaus.mojo. Record the plugins you find there and use the highest release. If you want to see what the most recent version in central is, then search or browse for your plugin on our <a href="http://repository.sonatype.org">public Nexus instance</a> and look for the highest non snapshot version.</p>

<p><em>So how does 2.0.9 fit into all of this?</em></p>

<p>Many users are not locking down their plugin versions for many different reasons. Because of this it is unfortunately common to see people having build issues pretty quickly after a plugin release.</p>

<p>For a long time, the Maven team resisted locking down the plugins in lieu of a better solution and user education. One of the prime reasons was as I mentioned earlier, forcing plugins to have a declared version was not newbie friendly. Unfortunately the better solution has yet to materialize and the users continued to have trouble.</p>

<p>Recognizing that we had to do something to ease the pain,  we came up with a fairly simple solution: provide default versions in the pluginManagement section of the superpom. We are, in effect, doing exactly what we teach in the classes. The benefit of doing this is that now core plugin versions will not &#8220;randomly&#8221; change on you unless you change your Maven version. Because local poms override inherited poms, this has no impact on builds that are already locking down their plugin versions.</p>

<p><em>What&#8217;s the fine print?</em></p>

<p>There are a few gotchas.</p>

<ul>
    <li>It&#8217;s not practical for us to track all the plugins in the Maven universe. What we have locked in the super pom are all plugins injected by the default lifecycles and a couple other common ones like assembly and dependency. Everything else is still subject to LATEST updates.</li>
    <li>You won&#8217;t get plugin updates for these core plugins at all until you upgrade Maven.</li>
    <li>Your build may not be reproducible in the future if you&#8217;re using a new version of Maven because the plugins will likely be different.</li>
    <li>If you upgrade to a new version of Maven and your build breaks, it won&#8217;t be immediately apparent if the core caused the issue, or if it&#8217;s one of the plugins that changed</li>
</ul>

<p>For these reasons and more, we highly recommend that you start taking control of your plugin versions and locking them down. This way you can try out one new plugin at a time, adjust if needed and then lock it. Once the 1.0 version of the enforcer plugin gets released this will be much easier to deal with. I&#8217;m also planning to share the code with the help plugin to make something like help:current-plugins.</p>

<p>There are several other exciting changes in 2.0.9 that are highlighted in the <a href="http://maven.apache.org/release-notes.html">release notes</a>.</p>

<p>In the meantime, the plan for 2.0.10 is laid out <a href="http://www.nabble.com/Planning-for-2.0.10-tt16591531s177.html#a16591531">here</a> and we are moving along, focused on killing regressions from older versions and fixing the popular issues so please vote on your favorite (or resented) <a href="http://jira.codehaus.org/browse/MNG">issues</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sonatype.com/people/2008/04/maven-209-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

