maven

作者: 金色的清晨 | 来源:发表于2019-08-28 11:22 被阅读0次

生命周期

内建3大阶段:clean,default,site

default阶段主要如下
validate,
compile,
test,
package,
integration-test,
verify,
install,
deploy,
中间还有很多小阶段,参考maven官网

定制流程

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

            <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已经集成了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>

相关文章

网友评论

      本文标题:maven

      本文链接:https://www.haomeiwen.com/subject/htkpectx.html