<?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; checkstyle</title>
	<atom:link href="http://blog.sonatype.com/people/tag/checkstyle/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.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>Thu, 16 May 2013 18:53:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>How to override a plugin&#039;s dependency in Maven</title>
		<link>http://blog.sonatype.com/people/2008/04/how-to-override-a-plugins-dependency-in-maven/</link>
		<comments>http://blog.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[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[<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://blog.sonatype.com/people/2008/04/how-to-override-a-plugins-dependency-in-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
