7

I'm looking for a way, to execute additional commands (e.g. a perl script) after running mvn archetype:generate on my custom archetype automatically.

Is this possible?

Context

I'm writing an archetype, that creates OSGi bundles which i want to integrate into a parent project as modules. After generating the bundle, i wish to organise it into the parents directory structure and then manipulate poms and other configuration files automatically.

This has been asked on maven forums before 1, however no answer was given.

thrau
  • 2,915
  • 3
  • 25
  • 32
  • Are you asking for something more complex than `Runtime.getRuntime().exec()`? – Nathaniel Waisbrot May 21 '13 at 01:14
  • that would do fine. however i do not know, how to hook this into the post-execution of the goal. – thrau May 21 '13 at 10:49
  • Why not just make the `exec` call in the main goal, after doing whatever Java-native steps you're doing? – Nathaniel Waisbrot May 21 '13 at 12:25
  • where and how would i call this? i want to run it implicitly after running archetype:generate. – thrau May 22 '13 at 09:14
  • You're writing the code for `generate`. Why don't you include the `exec` call in that code? Is there something that you need to happen *after* your main archetype code runs but *before* other goals? – Nathaniel Waisbrot May 22 '13 at 15:03
  • i'm sorry you've lost me. i'm not writing the code for the maven goal, i'm running the predefined maven archetype goal "generate". all i'm currently doing is editing the archetype resources. – thrau May 22 '13 at 22:26
  • 1
    My fault. The only time I wrote an archetype in Maven, I wrote it as a full-fledged plug-in (because I needed to do more than simple templates). I completely forgot that there is a simpler system. Anyway, for what you're doing, I think the answer is "no" for the same reasons given in http://stackoverflow.com/questions/16264059/maven-bind-plugin-execution-to-the-execution-of-another-plugin-not-to-a-lifecy – Nathaniel Waisbrot May 23 '13 at 02:41

1 Answers1

2

Thrau, you can invoke mojo post execution of archetype:generate by adding -Dgoals="your custom mojo plugin", within the plugin you can write your custom code. Hope this helps.

Thiru
  • 333
  • 2
  • 8