创建一个新阶段 [英] Creating a new phase

查看:73
本文介绍了创建一个新阶段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Maven进行一个项目,为此我需要两个新阶段:分析"和评估"(用于数据分析的不同阶段).我已经阅读了所有可以找到的文档,并创建了components.xml和lifecycle.xml的版本,这些版本与我所能纠正的尽可能接近,但是Maven拒绝运行新阶段. (我应该强调的是,让我的插件正常工作没有问题,并且将它们绑定到默认生命周期提供的现有阶段也没有问题.我的问题是,我创建的新阶段似乎被maven忽略了.)需要做一些工作才能使我的新阶段正常工作吗?

I am working on a project using Maven for which I need two new phases: 'analyze' and 'eval' (for different phases of data analysis). I've read all the docs I can find, and created versions of components.xml and lifecycle.xml that are as close as I can get to correct, but Maven refuses to run the new phases. (I should emphasize that I have no problem getting my plugins to work, and no problem binding them to the existing phases provided by the default lifecycle. My problem is that the new phases I create seem to be ignored by maven.) What do I need to do to get my new phases to work?

lifecycles.xml:

lifecycles.xml:

<lifecycles>
  <lifecycle>
    <id>lenskit</id>
    <phases>
      <phase>
        <id>analyze</id>
        <executions>
          <execution>
            <goals>
              <goal>greet</goal>
            </goals>
          </execution>
        </executions>
      </phase>
      <phase>
        <id>validate</id>
        <executions>
          <execution>
            <goals>
              <goal>greet</goal>
            </goals>
          </execution>
        </executions>
      </phase>
    </phases>
  </lifecycle>
</lifecycles>

components.xml:

components.xml:

<component-set>
  <components>
    <component>
      <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
      <role-hint>lenskit</role-hint>
      <implementation>
        org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
      </implementation>
      <configuration>
         <id>lenskit</id>
         <phases>
            <phase>get-data</phase>
            <phase>analyze</phase>
            <phase>eval</phase>
         </phases>
         <default-phases>
            <verify> org.apache.maven.plugins:maven-resources-plugin:resources </verify>
            <get-data> org.riedl:hello-lenskit-plugin:greet </get-data>
            <analyze> org.riedl:hello-lenskit-plugin:greet </analyze>
            <eval> org.riedl:hello-lenskit-plugin:greet </eval>
            <package> org.riedl:hello-lenskit-plugin:greet </package>
         </default-phases>
      </configuration>
    </component>
  </components>
</component-set>

推荐答案

Maven邮件列表中的一个向导将我引向了一个完整的工作示例,该示例完全满足了我的要求:它创建了一个自定义生命周期,其命名阶段为您定义的任意阶段并允许您从maven命令行使用该生命周期.该示例位于:

One of the wizards on the Maven mailing list pointed me to a complete working example that does exactly what I wanted: it creates a custom lifecycle with phases named whatever you want, and lets you use that lifecycle from the maven command-line. The example is at:

https://svn.apache.org/repos/asf /maven/plugins/trunk/maven-scm-publish-plugin

缺少的主要见解是,components.xml文件必须同时具有 一个LifecycleMapping组件一个Lifecycle组件.正确的,可以正常工作的components.xml如下.

The key missing insight is that the components.xml file must have both a LifecycleMapping component and a Lifecycle component. The correct, working components.xml is below.

请注意,您只能定义其他生命周期(即,除了三个 default 生命周期(构建,清理和站点生命周期)之外的其他生命周期).原始生命周期及其阶段将始终存在,并且您不能在新生命周期中包含任何名称与现有生命周期相匹配的阶段,这太糟糕了,因为它使为项目重新定义完整生命周期变得更加尴尬.不过,这是向前迈出的不错的一步.

Note that you may only define an additional lifecycle (i.e. additional to the three default lifecycles: the build, clean and site lifecycles). The original lifecycles and their phases will always be present and you cannot include any phases with names that match an existing lifecycle in your new lifecycle, which is too bad, since it makes it more awkward to redefine a complete lifecycle for a project. Still, this is a nice step forward.

另外,请记住,在使用新生命周期时,必须将其标记为扩展名:

Also, remember that when you use the new lifecycle, you must mark it as an extension:

<extensions>true</extensions>

因此允许该插件重新定义生命周期.为了表明您的pom.xml应该使用新的生命周期,请将生命周期名称作为项目的包装".

so the plugin is allowed to redefine the lifecycle. To indicate that your pom.xml should use the new lifecycle, include the lifecycle name as the "packaging" for your project.

<component-set>
  <components>
    <component>
      <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
      <role-hint>lenskit</role-hint>
      <implementation>
    org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
      </implementation>
    </component>
    <component>
      <role>org.apache.maven.lifecycle.Lifecycle</role>
      <implementation>org.apache.maven.lifecycle.Lifecycle</implementation>
      <role-hint>lenskit</role-hint>
      <configuration>
     <id>lenskit</id>
     <phases>
        <phase>get-data</phase>
        <phase>analyze</phase>
        <phase>eval</phase>
     </phases>
     <default-phases>
        <get-data>org.riedl:hello-lenskit-plugin:greet</get-data>
        <analyze>org.riedl:hello-lenskit-plugin:greet</analyze>
        <eval>org.riedl:hello-lenskit-plugin:greet</eval>
     </default-phases>
      </configuration>
    </component>
  </components>
</component-set>

这篇关于创建一个新阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆