aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Maven alternate/custom lifecycle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Maven alternate/custom lifecycle" Watch "Maven alternate/custom lifecycle" New topic
Author

Maven alternate/custom lifecycle

Antonio Fornie
Ranch Hand

Joined: Aug 07, 2008
Posts: 117
Hi,

I need to have a new lifecycle for Maven 2, in which I define my own phases. Does anybody know how to do this?

Do I need to introduce changes in the poms? Because I would like not to touch anything in my already working poms, just create a new custom lifecycle, with new phase for which I can create plugins, but avoiding changes in every pom IF POSSIBLE.

Thank you very much!

antonio


I feel there must be far better ways to do what I do... that makes learning even funnier
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

I would read Maven the Definitive Guide as a primer on how to start doing this.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Antonio Fornie
Ranch Hand

Joined: Aug 07, 2008
Posts: 117
Yes that's always one of my first references, but I didn't find what I want, I think it's not possible.

I can do something like the following, just in case anybody wants to know it. Maven installation brings a jar (uber) which defines the lifecycles in the file uber.jar/META-INF/plexus/components.xml. There you should define a knew lifecycle with its own id and own phases. Then you'll have to define default goals (plugin:goal) for each phase.

You can define goals already defined for other lifecycles, but you cannot repeat phase names. The problem is that even when I declare here that I will use MyPlugin:MyGoal in the phase MyPhase of a new custom lifecycle, I'll have to modify dozens of projects's pom.xml files if I want them to have the behavior they used to have for common phases in my phases. I mean, I can add this to components.xml

<id>my_lifecycle</id>
<phases>
<phase>my_deploy</phase>
</phases>
</lifecycle>

But not this

<id>my_lifecycle</id>
<phases>
<phase>deploy</phase>
</phases>
</lifecycle>

Because I'm using a phase name already used for default lifecycle: deploy.

My scenario is there are hundreds of projects that include a pom with lot of info about compilation, testing... AND DEPLOYMENT. But as it takes so long any of these phases, I want to create a custom lifecycle that just go directly to deploy phase (the same as default lifecycle but without phases prior to pdeployment), that way I can invoke the default lifecycle until install phase and leave it all prepared sometime before deployment, in order to be fast when it comes to actually deploy the app because it wouldn't go through previous phases.

Whith my solution I would have to mention the phase my_deploy in hundreds of pom.xml files as all of them have a lot of info related to deploy phase now... I think my best choice would be to invoke mvn deploy skipping all the previous phases.

I hope anybody found this topic worth reading. Best regards and thank you very much as always.

antonio
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Going out on a limb here, but maybe you can use a profile to execute the alternative behaviour in the same phase?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maven alternate/custom lifecycle
 
Similar Threads
Configure Hudson to build from Eclipse local worspace
Ant, Maven, Maven2 or other
getting maven to create my DB before tests are run
Apple secretly updated Ant and Maven
Publish to maven repository as "latest"