tags:

views:

56

answers:

2

I have a parent POM with a bunch of child modules. I want to run an antrun:run task after all the children have executed a package task (I'm using Ant to package my app since i gave up figuring out how to get assembly to work correctly).

I need to have the antrun task execute after all the children - but I can't associate it with package phase since parent gets "packaged" before children, and i need ant to run afterwards.

Is there a way to do it in one command?

Easy workaround, of course, is to run 2 maven commands:

mvn package; mvn antrun:run

But i want to do it in one, if possible

mvn package antrun:run

produces wrong behaviour - it runs antrun:run before child projects' package phase.

Ideally, i'd be able to just type

mvn package

And have that run package phase on all children, and then run antrun:run on parent.

+1  A: 

I need to have the antrun task execute after all the children - but I can't associate it with package phase since parent gets "packaged" before children, and i need ant to run afterwards.

Create another module that depends on all children (so that it will be the last project during a reactor build) and bind your antrun stuff on package in this module. Then just run mvn package from the root project.

Pascal Thivent
Genius! i imagine it's not _most maveny_ way to do it, but it certainly works.Interestingly, i just put my new _packager_ module at the end of modules list, and I didn't have to even depend on anything - it just worked.thanks for the suggestion.
toli
@toli: You're welcome. But I warmly suggest to declare the dependencies explicitly so that the build order will be calculated in a reliable way. It currently works "by accident".
Pascal Thivent
A: 

First you have to specify execution for antrun plugin. This will automate the run of that plugin.

Then you have to push maven to run package plugin before antrun plugin. You can do that when you place package plugin setup before antrun plugin setup.

Setup example:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
  </plugin>
  <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.4</version>
    <executions>
      <execution>
        <phase> package </phase>
        <configuration>
          <tasks>

            <!--
              Place any Ant task here. You can add anything
              you can add between <target> and </target> in a
              build.xml.
            -->

          </tasks>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
amra
I do have exactly your above setup in my POMnot quite sure what you mean by:_Then you have to push maven to run package plugin before antrun plugin. You can do that when you place package plugin setup before antrun plugin setup._i don't have a setup for package plugin... so how do i _push it_ to be earlier?
toli
@toli: You can't "push" anything to be earlier, the default bindings (that you can't "unbind") will always run **before**, period. And there is no *package plugin*.
Pascal Thivent