user2942568
user2942568

Reputation: 1

Maven build with multiple exec plugin executions, ant tasks

I have to perform following steps in my maven build, in the specific order mentioned below:

  1. exec-maven-plugin
  2. maven-antrun-plugin
  3. exec-maven-plugin
  4. maven-antrun-plugin
  5. maven-remote-resources-plugin, jaxb2-maven-plugin
  6. maven-javadoc-plugin
  7. exec-maven-plugin

I have to use JDK 6, so using Maven 3.2.1.

In the pom file, I have defined 5 different profiles for #1, #2, #3, #4, #7 above (profile ids: p1, p2, p3, p4, p5). I am building my project using multiple commands:

  1. mvn exec:exec -Dp1 (for #1 above)
  2. mvn antrun:run -Dp2 exec:exec -Dp3 (for #2 and #3 above)
  3. mvn antrun:run -Dp4 (for #4 above)
  4. mvn clean install (for #5, #6 above and compile classes)
  5. mvn exec:exec -Dp5 (for #7 above)

The build works okay with multiple commands, but is it possible to execute all steps using one command i.e. mvn clean install ?

What I understand is, it is not possible to have multiple executions of exec-maven-plugin in non consecutive order, hence I used profiles and then execute each step using the profile id. Reference: Maven maven-exec-plugin multiple execution configurations

Upvotes: 0

Views: 1245

Answers (1)

Andreas Sewe
Andreas Sewe

Reputation: 1638

What I understand is, it is not possible to have multiple executions of exec-maven-plugin in non consecutive order, hence I used profiles and then execute each step using the profile id.

The “profile trick” mentioned elsewhere is only needed when performing explicit goal invocation from the command line.

From what I gather, however, you would rather have your goals executed as part of a normal mvn clean install. In that case, you are in luck: Simply bind each goal to an appropriate phase in the default lifecycle. Depending on what your steps do, you may, e.g., bind the first <execution> of exec:exec (step 1) to the generate-sources phase. If the first <execution> of antrun:antrun (step 2) is then bound to, say, the process-sources phase, it will be called after step 1 as executes the goals bound to all phases up to install.

Building a project like this with a single mvn install is what Maven was designed to do; having to call mvn five times to build one project is definitely not the Maven Way.

That being said, you may run out of phases if all your steps logically belong to, say, the package phase. In that case, the steps are executed in the order in which their <execution> elements are listed in the pom.xml.

Upvotes: 0

Related Questions