3

I have a multi-module maven project (several levels of nesting). Normally, when I execute a maven build (like mvn install or whatever), maven will run all the goals for the parent project before proceeding with the children.

I want to be able to define a goal that runs on the parent, but not until all of the children have been processed. Is there a way to do this?

Specifically, what I want to do is run an exec:exec goal which recurses down the filesystem looking for test result files and copies them to a central location for aggregation by our CI system (cruisecontrol). So, alternative solutions to this problem are also welcome :)

UPDATE: I forgot to mention one requirement: I need the exec goal to run regardless of whether the build is successful or not.

Kris Pruden
  • 3,280
  • 4
  • 25
  • 30

4 Answers4

2

I don't think it's possible to do things from the parent at the end of a multi-modules build (this is just not how things work). However, did you consider adding a module (that could be of type pom) depending on all child projects (so it will be the "last" project in a reactor build) and run exec:exec in this module? I may be missing something be I don't see why this wouldn't work.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • This works in basic situations, but fails in case when modules are e.g. Spring Boot Applications. Those don't make good dependencies. – Zajo Oct 24 '17 at 15:54
2

Based on the other answers and my own subsequent investigation, it doesn't look like what I described is possible with Maven.

However, I was able to solve my problem, although the solution is specific to cruisecontrol. Basically, I bound my exec goal to the pre-site phase then specified pre-site as the sitegoal in my cruisecontrol configuration. The sitegoal runs after the main goal, and does so regardless of whether the build succeeds or not.

I imagine other CI systems offer something similar..

Kris Pruden
  • 3,280
  • 4
  • 25
  • 30
1

Sounds more like a reporting plugin. Creating a Maven plugin is actually quite easy.

0

Why not have a antrun copy step attached to the verify phase of each sub project to copy the results up to the parent location. You could then have a similiar step in the parent to do the CI aggregation.

Alternatively, you could have each sub project do its own CI integration using a simliar techneque.

We currenyly use the technique to generate websphere ejb stubs for a jar, amongst other things.

Michael Rutherfurd
  • 13,815
  • 5
  • 29
  • 40