maven项目使用jacoco插件检测代码覆盖率详细配置
使用maven构建项目(java项目或者web项目都可以)
jacoco插件的配置参考官方网址:http://www.eclemma.org/jacoco/trunk/doc/maven.html
(1)配置jacoco的依赖jar包
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
</dependency>
(2)配置jacoco的插件,以及相关的goal
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
<!--这里的execution ,每一个执行的goal,对应的id必须是唯一的-->
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!--这个check:对代码进行检测,控制项目构建成功还是失败-->
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
<!--这个report:对代码进行检测,然后生成index.html在 target/site/index.html中可以查看检测的详细结果-->
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
(3)配置代码检查的约束 rules
<!-- Configuration 里面写配置信息 -->
<configuration>
<!-- rules里面指定覆盖规则 -->
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>BUNDLE</element>
<limits>
<!-- 指定方法覆盖到80% -->
<limit implementation="org.jacoco.report.check.Limit">
<counter>METHOD</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
<!-- 指定指令覆盖到80% -->
<limit implementation="org.jacoco.report.check.Limit">
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
<!-- 指定行覆盖到80% -->
<limit implementation="org.jacoco.report.check.Limit">
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
<!-- 指定类覆盖到100%,不能遗失任何类 -->
<limit implementation="org.jacoco.report.check.Limit">
<counter>CLASS</counter>
<value>MISSEDCOUNT</value>
<maximum>0</maximum>
</limit>
</limits>
</rule>
</rules>
</configuration>
(4)完整的pom.xml的配置如下
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>cn.demo</groupId>
<artifactId>answers</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>answers</name>
<url>http://maven.apache.org</url> <build>
<finalName>answers</finalName>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${compiler.source}</source>
<target>${compiler.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin> <!--检查代码覆盖率的插件配置-->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions> <!-- Configuration 里面写配置信息 -->
<configuration>
<!-- rules里面指定覆盖规则 -->
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>BUNDLE</element>
<limits>
<!-- 指定方法覆盖到80% -->
<limit implementation="org.jacoco.report.check.Limit">
<counter>METHOD</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
<!-- 指定指令覆盖到80% -->
<limit implementation="org.jacoco.report.check.Limit">
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
<!-- 指定行覆盖到80% -->
<limit implementation="org.jacoco.report.check.Limit">
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
<!-- 指定类覆盖到100%,不能遗失任何类 -->
<limit implementation="org.jacoco.report.check.Limit">
<counter>CLASS</counter>
<value>MISSEDCOUNT</value>
<maximum>0</maximum>
</limit> </limits>
</rule>
</rules>
</configuration>
</plugin> </plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.source>1.7</compiler.source>
<compiler.target>1.7</compiler.target>
<junit.version>4.12</junit.version>
</properties> <dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
maven项目使用jacoco插件检测代码覆盖率详细配置的更多相关文章
- jenkins使用jacoco插件检测代码覆盖率(八)
代码覆盖率:类覆盖,方法覆盖,行覆盖,指令覆盖……(简而言之,就是判断有没有被执行) 覆盖率 = 已经执行的代码 / 总代码 (1)创建maven项目,配置pom.xml如下 pom.xml < ...
- 关于执行findbugs,checkstyle,jacoco插件检测代码,GitHook的脚本编写
Git钩子的作用: (pre-commit ) 在用户执行 git commit -m "xxx" 命令之前,先执行pre-commit文件中的脚本命令 在pre-commit文件 ...
- Java Maven项目使用CXF插件生成WebService代理
CXF生成代理类插件名称:cxf-codegen-plugin 实现功能: 指定代理类所在的包 生成soapheader 操作: eclipse中run as -> maven build -& ...
- ANT 发布项目中 build.xml 文件的详细配置
xml 代码 <?xml version="1.0" encoding="UTF-8"?> <!-- name:对应工程名字 default: ...
- Intellij热部署插件JRebel的详细配置及图解
参考博客地址:https://blog.csdn.net/nyotengu/article/details/80629631 参考博客地址:https://blog.csdn.net/weixin_4 ...
- IDEA热部署(二)---jetty插件启动maven项目
jetty插件的配置 我们使用jetty插件来进行启动我们的maven项目,在pom.xml中进行配置: <plugins> <plugin> <groupId>o ...
- 使用maven的插件进行maven项目的打包
1 maven项目打包的插件有3种 maven-jar-plugin maven-assembly-plugin maven-shade-plugin 2 maven-jar-plugin 现在要新增 ...
- Gradle 1.12用户指南翻译——第三十四章. JaCoCo 插件
本文由CSDN博客万一博主翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...
- mybatis 学习一 建立maven项目
一.直接建立Maven项目方法 1.建立Maven项目 接下来使用Eclipse的maven构建一个web项目,以构建SpringMVC项目为例: 1.1 选择建立Maven Project 选择Fi ...
随机推荐
- Heroku 如何上重置 PostgreSQL 数据库
如果你要在 Heroku 上重置 PostgreSQL 数据库,可以使用以下命令 : $ heroku pg:reset DATABASE $ heroku run php artisan mig ...
- Oracle loop循环无法插入数据
以下的测试基于scott用户下的emp表 首先用while循环进行测试,向emp表插入999条数据 declare i emp.empno; begin loop insert into emp(em ...
- python3之装饰器
1.装饰器 装饰器本质上是一个python函数,它可以让其他函数在不需要做任何代码变动的前提下增加额外功能,装饰器的返回值也是一个函数对象.它经常用于有切面需求的场景,比如:插入日志.性能测试.事务处 ...
- 一句话理解字符编码(Unicode ,UTF8,UTF16)
Unicode和ASCII码属于同一级别的,都是字符集,字符集规定从1到这个字符集的最大范围每个序号都各表示什么意思.比如ASCII字符集中序号65表示"A". 那接下来的UTF8 ...
- PE文件简介
PE文件的全称是Portable Executable,意为可移植的可执行的文件,常见的EXE.DLL.OCX.SYS.COM都是PE文件,PE文件是微软Windows操作系统上的程序文件(可能是间接 ...
- HTML知识点总结之img、scirpt、link标签
<img>元素 使用<img>可以在网页插入一个图片,但实际上<img>标签并不会在网页中直接插入图像,而是从网页上链接图像. <img>的主要属性 ( ...
- python 版本管理工具 pyenv 使用备忘
安装步骤 安装 xcode-select 以及 homebrew(前者在安装 git 的时候装过,后者 mac 开发必备无需解释) 安装 pyenv brew install pyenv,用 pyen ...
- Vivado常见问题集锦
5. Vivado软件更新新版后更新IP 当更新到新版本的Vivado后,之前的一些工程的IP是不能直接打开使用的,这个时候我们只需要使用新版本的Vivado更新一下每个工程的IP即可,使用新版本Vi ...
- spring官方学习地址
1.http://projects.spring.io/spring-framework/ 2.https://github.com/spring-projects/spring-mvc-showca ...
- python模块安装
现在终于知道怎么在windows上导入Python的第三方模块了 首先在DOS下进入Python安装的pip目录:D:/Python27/Scripts 用pip install XXX安装 之前一直 ...