Maven : what does “build life cycle mapping” mean
-
19-06-2021 - |
سؤال
I have been trying to understand the concepts of Maven and I find it difficult to understand the terminology used.
I came across this term "build life cycle mapping
". Could anybody give me a clear view on what this term means? I know what build life cycle
is, but what does it mean when we use "mapping
" with it?
Thanks in advance for any help
Update: this is where i found this term- Project build lifecycle mapping
المحلول
OK, so as you know, Maven provides kind of build lifecycle, that is sequence of phases, that starts with such basic stuff as validating POMs, generating sources (if there is a need) or compiling classes, and ends with installing stuff into local repository and deploying artifacts on remote repos. What is important, this is a sequence, so order matters here. If you invoke some phase (let's say install
) then all phases from the beginning to the install
are executed, one after another.
Now, these lifecycle's phases are some general ideas about what steps every software project needs to perform to be built, as we usually consider this. And as you know, software artifacts can have many different natures and so need quite specific stuff to be done in every phase. That's what lifecycle mapping is. It is binding between lifecycle's phases and concrete plugins' goals that is specific for artifact's nature (which means packaging
in Maven world).
So, for example, this mapping for jar
packaging says that we need to call maven-compiler-plugin:compile
in compile
phase, but ear
packaging says that we need to call nothing in its compile
phase. Look here for more examples.
نصائح أخرى
I'd recommend you to start with this article on Maven official web-site.
To put it simple, each project depending on its packaging has a number of phases and a number of default plugins bound to these phases that execute during the build. For example, during compile
phase maven-compiler-plugin
compiles all sources located in src/main/java
(if not specified otherwise). If plugin is not bound to default lifecycle (e.g. it is some custom plugin), then you have to include it into build and map it to some specific phase yourself (the second is optional since most of the custom plugins have defaul mapping of their goals to some specific phases, for example jspc-maven-plugin
binds its goal compile
to compile
phase of the lifecycle by default).
So mapping in this context specifies which plugin-goal pair executes on each phase of the project build.