Custom maven plugin development – plugin execution not covered by lifecycle configuration

You are creating a custom maven plugin, everything works but when it comes to using it in a maven module inside Eclipse, m2eclipse plugin cries with message – “plugin execution not covered by lifecycle configuration”.

Now one could find a lot of documentation on how to get around with this error while using a third-party plugin, but what about if you yourself are creating a maven plugin. You would like to fix it before it comes in front of your custom-plugin users.

I was very confused with the existing documentation on how to fix it. So now as finally I fixed it, let me share it with you and come to the point.

One needs to have “src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml” file inside custom maven plugin. This file determines the action of your plugin with respect to Eclipse activities.

If you want to tell m2e to silently ignore the plugin execution with respect to any Eclipse activities, here’s what you may want to add in this file.

<lifecycleMappingMetadata>
  <pluginExecutions>
    <pluginExecution>
      <pluginExecutionFilter>
        <goals>
          <goal>some-goal</goal>
        </goals>
      </pluginExecutionFilter>
      <action>
        <ignore />
      </action>
    </pluginExecution>
  </pluginExecutions>
</lifecycleMappingMetadata>

If you want your plugin to execute at the time of partial or full Eclipse build, you will have following configuration:

<lifecycleMappingMetadata>
  <pluginExecutions>
    <pluginExecution>
      <pluginExecutionFilter>
        <goals>
          <goal>some-goal</goal>
        </goals>
      </pluginExecutionFilter>
      <action>
        <execute>
          <runOnIncremental>see below</runOnIncremental>
          <runOnConfiguration>see below</runOnConfiguration>
        </execute>
      </action>
    </pluginExecution>
  </pluginExecutions>
</lifecycleMappingMetadata>

If <runOnIncremental/> is set to true (the default), corresponding mojo will be executed during both full and incremental workspace builds. If set to false, the mojo will be executed during full workspace build only.

If <runOnConfiguration/> set to true, corresponding maven mojos will be executed as part of project import and configuration update.

ShriKant Vashishtha is an enterprise Agile Coach, IT strategist, trainer, thinker and hands-on geek. He is passionate towards enterprise Agile transformation, quality aspect of software development including TDD, refactoring, Continuous Delivery, DevOps and Test Automation. He can be reached at vashishtha_sk@yahoo.com.

Posted in Eclipse, Java, Maven, QuickTip

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge

Welcome to Sampreshan
Technology Strategist, Speaker, Scrum/XP/Agile Trainer Coach and Trainer
Your interest areas
Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: