Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a new phase

Tags:

maven

maven-3

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

<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> 
like image 415
John Riedl Avatar asked Sep 14 '12 23:09

John Riedl


People also ask

What is a phase in Revit?

Phases are a great tool in Revit to filter elements by stages in a project. The obvious phases are Existing and New. If you have worked on renovation projects or an addition to an existing building, I'm sure you know the importance of differentiating what is existing and new.

How do you show different phases in Revit?

Click Manage tab Phasing panel (Phases). In the Phasing dialog, click the Phase Filters tab. Click New to insert a new phase filter.


1 Answers

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

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.

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> 

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> 
like image 133
John Riedl Avatar answered Oct 02 '22 12:10

John Riedl