jacoco maven 多模块项目 单测代码覆盖率统计

1、说明-使用插件

maven-surefire-plugin

jacoco-maven-plugin

要求:版本大于0.7.7 同时配置report-aggregate参数

2、使用方法

2.1、第一步:parent.pom.xml 中声明

 <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.pluginsgroupId>
                    <artifactId>maven-surefire-pluginartifactId>
                    <version>2.19.1version>
                plugin>
                <plugin>
                    <groupId>org.jacocogroupId>
                    <artifactId>jacoco-maven-pluginartifactId>
                    <version>0.7.9version>
                plugin>
           plugins>
pluginManagement>

2.2、第二步:test 工程中加入:


 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-surefire-pluginartifactId>
            plugin>
            <plugin>
                <groupId>org.jacocogroupId>
                <artifactId>jacoco-maven-pluginartifactId>
                <executions>
                    <execution>
                        <id>prepare-agentid>
                        <goals>
                            <goal>prepare-agentgoal>
                        goals>
                    execution>
                    <execution>
                        <id>report-aggregateid>
                        <phase>verifyphase>
                        <goals>
                            <goal>report-aggregategoal>
                        goals>
                        <configuration>
                            <outputDirectory>${basedir}/../target/site/jacocooutputDirectory>
                        configuration>
                    execution>
                executions>
            plugin>
        plugins>
    build>

你可能感兴趣的:(java基础,maven)