生命周期
內(nèi)建3大階段:clean,default,site
default階段主要如下
validate,
compile,
test,
package,
integration-test,
verify,
install,
deploy,
中間還有很多小階段,參考maven官網(wǎng)
定制流程
在生命周期每個階段的功能上,定制如下流程:
- 靜態(tài)代碼檢測
代碼風(fēng)格檢測,maven-checkstyle-plugin,checkstyle.xml參考
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<violationSeverity>warning</violationSeverity>
</configuration>
</execution>
</executions>
</plugin>
- 編譯
指定jdk版本和文件編碼
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
單元測試
maven-surefire-plugin搜索*Test.java跑單元測試
-DskipTests=true 跳過集成測試
maven-failsafe-plugin 搜索*IT.java跑集成測試
-DskipITs=true 跳過打包
默認打的jar包,里面沒有依賴,只有你的代碼,需要在target目錄下運行,里面有依賴的class文件
如果獨立運行,打帶有依賴的uber_jar,需要maven-shade-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
如果是spring boot項目,spring-boot-maven-plugin已經(jīng)集成了shade插件
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>