maven

生命周期

内建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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。