maven

生命周期

內(nèi)建3大階段:clean,default,site

default階段主要如下
validate,
compile,
test,
package,
integration-test,
verify,
install,
deploy,
中間還有很多小階段,參考maven官網(wǎng)

定制流程

在生命周期每個階段的功能上,定制如下流程:

            <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>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。