Maven2 Lifecycle Help

Ive built a custom Maven2 plugin using Ant. I would like to name another plugin maven, in particular, the Cargo Maven2 plugin right after the successful completion of the custom Ant plugin. However, I do not want to attach the Cargo plugin to another goal or phase. Is there a way for them to be executed sequentially without the need to write a script package? Is a custom Ant plugin for the Cargo plugin being sent?

+3
source share
3 answers

See this discussion: Re: calling a plugin in another plugin? According to Maven developers, this does not mean that plugins should work.

However, there is an interesting comment:

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

Cargo is not only a Maven plugin, but also a Java API and Ant task . So you could:

  • call the Cargo Ant task from your Ant mojo (I think you only need the JAR for Cargo in your path to the plugin),

  • rewrite your w41-mojo in Java and call the Cargo API (you want to look at the sources of the Cargo plugin).

+2
source

The Ant script that runs maven-ant-plugin does not actually know Maven as such; This plugin is designed for backward compatibility with Ant user tasks. I can't think of a pure way to do what you want, although there may be some kind of hack that allows you to do this.

It should also be possible to run a second instance of Maven from within Ant, which fulfills the pure purpose of Cargo, but in this case you may run into problems with locked files, etc. The way to do this is to simply use the tag in your Ant script and invoke the mvn executable with the appropriate goals as arguments.

The cleanest way is to simply bind the Cargo target to the build phase and execute this run after Ant completes. I do not see a flaw in this approach - you have not actually indicated any specific reasons why you want to avoid this.

0
source

You may be interested in the following two maven

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

I used them in several custom maven plugins and I did not find an easier way to write and combine mojos.

0
source

All Articles