ChatGPT解决这个技术问题 Extra ChatGPT

What is the "reactor" in Maven?

I've been reading about Maven reactor and am confused by its terminology usage. I've read that a multi-module is a reactor, that you can manipulate the maven reactor and that the reactor is a plugin. What exactly is the reactor?


M
Manuel Jordan

The reactor is the part of Maven that allows it to execute a goal on a set of modules. As mentioned in the Maven 1.x documentation on multi-modules builds (the reactor concept was already there in Maven 1.x), while modules are discrete unit of work, they can be gathered together using the reactor to build them simultaneously and:

The reactor determines the correct build order from the dependencies stated by each project in their respective project descriptors, and will then execute a stated set of goals. It can be used for both building projects and other goals, such as site generation.

As explained, the reactor is what makes multi-module builds possible: it computes the directed graph of dependencies between modules, derives the build order from this graph (that's why cyclic dependencies are disallowed, which is good thing anyway) and then executes goals on the modules. In other words, a "multi-modules build" is a "reactor build" and a "reactor build" is a "multi-modules build".

In Maven 2.x, the support of multi-module builds has been very much improved and the reactor has become transparent to Maven users. But it's still there and is used under the hood.

In September 2008 (i.e. a long time after the rollout of Maven 2), a reactor plugin has been created to make it possible to interact (again) more closely with the Maven reactor. Brett Porter blogged about it in Reactor: My New Favourite Maven Plugin.

Most of the reactor plugin features are now natively supported (since Maven 2.1.0). See Maven Tips and Tricks: Advanced Reactor Options.


Why does the maven site say that this plugin is "retired"?
Because the reactor plugin is a plugin which (only) "talks" to the actual reactor. So not the reactor itself is retired but a plugin related to it.
M
Manuel Jordan

Reactor is used when a project have multi-modules.

The work done by reactor is:

Collecting the module details

Sorting the order based on dependencies

Building the projects in order

Starting with the 2.1 release, there are new command line options which allow you to manipulate the way Maven will build multi-module projects. These new options are:

-rf, --resume-from
    Resume reactor from specified project
-pl, --projects
    Build specified reactor projects instead of all projects
-am, --also-make
    If project list is specified, also build projects required by the list
-amd, --also-make-dependents
    If project list is specified, also build projects that depend on projects on the list  

More details:

Maven Tips and Tricks: Advanced Reactor Options