This is probably the most difficult topic to understand in Maven.
There is never a good way to explain it, and it leaves users confused and scared.
But let us try to understand it anyways.
Whenever you ask Maven to run a build, it looks at the packaging target (jar/war/whatever) and accordingly selects a build "lifecycle".
A lifecyle is a series of steps Maven will run to execute the build. Each of these steps is called a "phase" in the lifecycle.
To execute each phase, it will call a "plugin".
A plugin itself executes a series of steps. Each step of a plugin is called a "goal".
So, to sum it up, a build looks like this:
- Maven checks packaging
-- Selects lifecycle
---- Executes phases of the lifecycle
------- Each phase selects a plugin
---------- Plugin executes its goals
So far, it is probably easy to understand.
By default, Maven uses its built-in plugins.
Now for the confusing part.
You can ask Maven to run your own plugins - there are 100s of 3rd party plugins available which do all kinds of stuff.
Not only can you choose a plugin to run, you can specify which lifecycle phase you want to associate it with.
So when Maven reaches a particular phase in the lifecycle, it will execute your plugin (in addition to the default built-in plugin).
You can associate any number of plugins with a phase.
And you can associate a plugin with any number of phases!
This is why it gets so confusing.
Because, each time you use a plugin, you are making Maven deviate from its conventional build path to accommodate your specific plugins.
The more plugins you use, the more you deviate.
Each deviation is expensive in terms of pom maintenance. Because you have to worry about correctly configuring the plugin, updating its version, understanding the relation between plugins, make sure one plugin does not break the other, so on and so forth. Not to mention that it makes the pom longer and longer and that much more difficult to understand!
But instead of understanding the cost of using plugins, people freely use them. This defeats the whole Maven idea of convention over configuration. Very soon it becomes configuration over convention, and all the beautiful advantages of maven are lost!
So try to use plugins with care!
No comments:
Post a Comment