简体   繁体   中英

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.

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: 示例多模块项目结构

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM