views:

804

answers:

3

I’ve built a custom Maven2 plug-in using Ant. I would like to call another maven plug-in in particular the Cargo Maven2 plug-in immediately after the custom Ant plug-in successfully completes. However, I do not want to attach the Cargo plug-in to another goal or phase. Is there a way to have them run consecutively without having to write a batch script? Is there away to have the Custom Ant plug-in call out to the Cargo plug-in?

A: 

The Ant script that the maven-ant-plugin executes is not really aware of Maven as such; this plugin is designed for backwards compatibility with custom Ant tasks. I cannot think of a clean way of doing what you want though there may be some kind of hack that allows you to do it.

It should also be possible to execute a second instance of Maven from inside Ant, which runs purely the Cargo goal, but in that case you might encounter problems with locked files and the like. The way to do it would be to just use an tag in your Ant script and call the "mvn" executable with the appropriate goals as arguments.

The cleanest way is to simply bind the Cargo goal to a phase of the build, and have that run after Ant is finished. I do not see any disadvantage to that approach - you haven't really stated any specific reasons why you want to avoid it.

Pavel
+2  A: 

See this discussion: Re: calling plugin in another plugin? According to the Maven developers, this is not the way plugins are supposed to work.

However, there is this interesting comment:

Plugins/Mojos should be thin wrappers around a library. You'd want to use the library directly.

Cargo is not only a Maven plugin, it also has a Java API and an Ant task. So you could probably:

  • call the Cargo Ant task from your Ant mojo (I think you'll just need the Cargo JARs in your plugin's classpath);

  • rewrite your Ant mojo in Java, and invoke the Cargo API (you'd want to look at the sources of the Cargo plugin).

Olivier
A: 

You might be interested in the two following maven

The GMaven plugin lets you write maven plugins using groovy. This gives you full access to ant using the Ant Builder, it is a very easy way to write ant scripts in Groovy. Then in this Groovy mojo you could call any maven mojo using the Mojo Executor.

I have used those in several custom maven plugin and I haven't found an easier way to write and combine mojos.

SaM