Maven has a set of abstract lifecycle; plugins are implementations of these lifecycle phases.
Complete project build process usually includes: clean, compile, test, package, integrated testing, validation, deployment.
Maven lifecycle includes: clean
, default
(build project), site
(generate project site). By lifecycle, I mean if lifecycle is in the sequence of A,B,C
, then to execute C
would force A
and B
to be executed beforehand. In maven, lifecycle is clean, compile, test, package, install
. Running package
would force compile
and test
to run before package
.
- clean:
pre-clean
,clean
(clean all files built last time),post-clean
; - default:
compile
,test
,package
,install
; - site:
pre-site
,site
,post-site
,site-deploy
;
example: plugin> source
Add this into a quickstart
created maven project’s pom.xml
:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
This would bind source
plugin with package
in maven lifecycle, as shown in <phase>package</phase>
in execution with the plugin coordinates: groupId
, artifactId
w. specific goal
.
Run clean package
in Eclipse Run As Maven Build
.
This is the result of an execution:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building moduleName 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ moduleName ---
[INFO] Deleting /Users/.../workspace/moduleName/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ moduleName ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/.../workspace/moduleName/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ moduleName ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/.../workspace/moduleName/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ moduleName ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/.../workspace/moduleName/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ moduleName ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/.../workspace/moduleName/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ moduleName ---
[INFO] Surefire report directory: /Users/.../workspace/moduleName/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.imooc.projectName.moduleName.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ moduleName ---
[INFO] Building jar: /Users/.../workspace/moduleName/target/moduleName-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.848 s
[INFO] Finished at: 2020-01-01T17:40:26+08:00
[INFO] Final Memory: 17M/232M
[INFO] ------------------------------------------------------------------------
It’s seen that clean
, compile
, test
, source
are executed sequentially.