Jemolah
Jemolah

Reputation: 2192

How can I use Maven to automate multiple builds?

I have to manage multiple projects like A1..A5 and B1..B3. Each of the Bs depends on a specific set of the As. So I can start maven manually on every A then every B to create all jars. Starting Maven in one of the Bs will not even precompile the required As.

Is there any solution to do this just with Maven without additional tools like shell scripts or Ant?

And just to prevent answers like "move folder A into folder B": all folders are in one directory on the same level. That cannot be changed because different teams are working on this projects and each project has its own GIT repository.

Upvotes: 1

Views: 383

Answers (2)

leftbit
leftbit

Reputation: 838

If the As and Bs really are different projects you'll need some other tool like Jenkins to mangage and orchestrate your builds. Especially you'll be doing independent releases of the As and Bs, so you'll want to keep the Maven builds independent.

Upvotes: 0

Jens Bannmann
Jens Bannmann

Reputation: 5105

You may be able to get it to work like this:

  • create an "aggregator build": a POM project that lists the individual projects A1...A5 and B1...B3 as <modules> which is checked in to a separate git repository
  • in that git repository, configure git submodules which point to the other repositories

When starting a build on the aggregator project, Maven will automatically figure out the correct build order based on the dependencies of the included projects.

For example, given the following dependencies:

B1 uses A1 and A2
B2 uses A2 and A3
B3 uses A3, A4 and A5

Maven might come up with a build order of A1, A2, B1, A3, B2, A4, A5, B3.

Using Maven command line options, an aggregator build can even be started as "rebuild A3 and everything that uses it" or "rebuild everything needed for B1, then B1 itself".

However, all this may require that the individual projects inherit from the aggregator POM, which may or may not be feasible in your situation depending on what your POMs look like.

The directory structure could look like this: example multi-module project structure

Upvotes: 2

Related Questions