m2e 仍然给出错误“生命周期配置未涵盖插件执行”即使在自定义插件中有显式绑定

发布于 2024-12-26 03:33:14 字数 1545 浏览 3 评论 0原文

我正在构建一个插件来生成一些代码。

我已按照此处的步骤创建插件: http://maven.apache.org/guides/plugin/ Guide-java-plugin-development.html

插件来源:

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

用法:

    <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>

该插件本身工作正常,但在 Eclipse 中,我不断收到“生命周期未涵盖”错误。

我通读了“如何解决” Spring Data Maven 构建的生命周期配置未涵盖插件执行”,我假设如果我创建自己的插件并设置 @phase 和 @goal 注释,它将消除该错误。我真的不想在 pom.xml 中放入“lifecycleMappingMetadata”节点。

有人对此有什么建议吗?我需要为 m2e 编写一些特殊的内容才能消除该错误吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

说不完的你爱 2025-01-02 03:33:14

K. Claszen 的答案是正确的,但我想填写一些额外的细节。

A、m2e为什么会这样?

此行为的目的是防止 m2e 通过增量(且可能永无止境)更改消耗过多资源。

B. m2e 版本 1.1 还不是“版本”

目前 m2e 1.1 仍然是一个“里程碑”。
用户需要使用此更新站点安装/升级到它:
http://download.eclipse.org/technology/m2e/milestones/1.1
(我还必须卸载“m2e SCM 连接器”才能升级它)

现在,这对于您的用户来说可能比在其 pom.xml 文件中插入“快速修复”代码段更麻烦。但从长远来看,使用它是有好处的。

C. 使您的 Maven 插件与 m2e-1.1 兼容的概述

正如 K. Claszen 所描述的,大部分信息都在这里: M2E 兼容的 Maven 插件

一些关键点:

  1. 执行信息在文件中定义 - src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml - 请参阅 M2E 兼容的 maven 插件 格式。
  2. 如果您启用了“增量执行”,您的 Mojo 将需要与 Maven API 正确通信:
    1. 指定对 org.codehaus.plexus/plexus-build-api/0.0.1 的依赖项(撰写本文时为当前版本)
    2. 使用 org.codehaus.plexus.build.incremental.BuildContext 来:
    3. 检查相关资源是否发生变化
    4. 通知Maven插件执行的相关写入操作,以便其知道编译源等

D. 替代方案

如果 1.1 对于您的用户来说不是一个现实的选择,您可以:

  1. 创建一个 'M2E Extension Eclipse 插件' (!!),又名 'M2E Con​​nector',并将其贡献给市场。祝你好运。
  2. 通知您的插件用户选择 M2E“快速修复”,然后手动将 行更改为 。还有其他 SO 问题/答案涵盖了这一点。

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.
花辞树 2025-01-02 03:33:14

我认为 M2E 兼容 Maven 插件 站点将为您提供所需的信息。请注意,这是从 m2e 版本 1.1 开始才起作用的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文