3

I'm building a plugin to do some code generation.

I've followed the steps here for how to create a plugin: http://maven.apache.org/guides/plugin/guide-java-plugin-development.html

Plugin Source:

/**
 * @goal helloworld
 * @phase generate-sources
 */
public class SampleMojo extends AbstractMojo
{
    @Override
    public void execute() throws MojoExecutionException, MojoFailureException
    {
        getLog().info("Hello, world.");
    }
}

Usage:

    <plugins>
        <plugin>
            <groupId>com.sample</groupId>
            <artifactId>sample-maven-plugin</artifactId>
            <version>0.0.1</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>                     
                    <goals>
                        <goal>helloworld</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

The plugin works fine on its own, but in Eclipse, I keep getting the "not covered by lifecycle" error.

I read through "How to solve “Plugin execution not covered by lifecycle configuration” for Spring Data Maven Builds" and I assumed that if I created my own plugin and set the @phase and @goal annotations it would get rid of that error. I really don't want to put in the "lifecycleMappingMetadata" node in the pom.

Anyone have any advice on this? Is there something special that I need to write for m2e to get that error to go away?

Community
  • 1
  • 1
timmyonline
  • 193
  • 13

2 Answers2

5

K. Claszen's answer is correct, but I'd like to fill out some extra details.

A. Why is m2e like this?

The point of this behaviour is to prevent m2e from consuming too many resources with incremental (& potentially never-ending) changes.

B. m2e version 1.1 is not a 'release' yet

Currently m2e 1.1 is still a 'milestone'. Users would need to install/upgrade-to it with this update site: http://download.eclipse.org/technology/m2e/milestones/1.1 (I also had to uninstall an 'm2e SCM connector' in order to upgrade it)

Right now, this is potentially more hassle for your users than inserting the 'Quick Fix' snippet in their pom.xml files. But, in the long-term it's good to use it.

C. Overview of making your maven plugin m2e-1.1-compatible

As described by K. Claszen, most of the info is here: M2E compatible maven plugins.

Some key points:

  1. Execution information is defined in a file - src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml - see M2E compatible maven plugins for format.
  2. If you have enabled 'incremental execution', your Mojo will need to communicate properly with the Maven API:
    1. Specify a dependency to org.codehaus.plexus/plexus-build-api/0.0.1 (current at time of writing)
    2. Use org.codehaus.plexus.build.incremental.BuildContext, to:
    3. Check whether relevant resources have changed
    4. Notify Maven about relevant write operations executed by the plugin, so that it knows to compile sources, etc.

D. Alternatives

If 1.1 isn't a realistic option for your users, you could:

  1. Create an 'M2E Extension Eclipse plugin' (!!), aka an 'M2E Connector', and contribute it to the marketplace. Good luck with that.
  2. Inform your plugin users to select the M2E 'Quick Fix', and then manually change the <ignore /> line to <execute />. There are other SO questions/answers which cover this.
laher
  • 8,860
  • 3
  • 29
  • 39
  • @amir75 i'm getting the same problem so i installed the m2e connectors but the problem persist , so i will use the other remedy proposed by the pom.xml overview i mean (permanently mark bundle in pom.xml as ignored in eclipse build ) so what should i put the tag – Amira Manai Jul 12 '12 at 11:55
  • replace `` with `` – laher Jul 18 '12 at 02:49
2

I think the M2E compatible maven plugins site will give you the information you need. Notice that this works first since m2e version 1.1.

FrVaBe
  • 47,963
  • 16
  • 124
  • 157
  • Thanks for the link, I was lost without it, but I have it working now. Please see my answer for extra details.. – laher Jan 19 '12 at 03:12