需求:jenkins在构建项目的时候完毕后,通过单元测试,获得覆盖率报告
在项目的pom.xml中引入插件,代码如下:
<plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>maven-clover2-plugin</artifactId> <version>2.4.3</version> <configuration> <!-- license可以是引入一个文件 <licenseLocation>/path/to/clover.license</licenseLocation> --> <license><![CDATA[ooqPUwNxjSoDqHnCngfktIWBNPqFPNpoRWmSQNtcXCBNsC mi2Klr>BubJuRkHMnsPmYWyQ2KaPcG2jKoj<lg<apUl<7h rQROvuppqQrQORRPPRNwxPQPnqprnqrpQmvxXswsTsTVQn mnmUUnopvnmoppqvvrUUnopvnmoppqvvrUUXYZabcUUn]]></license> </configuration> <executions> <execution> <id>main</id> <phase>verify</phase> <goals> <goal>instrument</goal> <goal>aggregate</goal> <goal>clover</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.4.3</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> <encoding>UTF-8</encoding> </configuration> </plugin>
可能在jenkins做覆盖率统计的时候会出错,有一些.java文件无法统计,解决办法,在pom.xml中加入一下代码:
在maven-clover2-plugin的<configuration>元素中添加: <encoding>UTF-8</encoding>
========================================================================
下面几个maven-plugin不知道其存在的意义,如果有知道的朋友,请科普下,小弟感激不尽!
<!-- maven project 报表插件 --> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <version>2.2</version> <configuration> <!-- 页面编码,设置与你匹配的编码 --> <encoding>utf-8</encoding> <charset>utf-8</charset> <inputEncoding>utf-8</inputEncoding> <outputEncoding>utf-8</outputEncoding> </configuration> </plugin> <!-- surefire 单元测试一览 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> <version>2.6</version> <configuration> <encoding>utf-8</encoding> <charset>utf-8</charset> </configuration> </plugin> <!-- JDepend 代码分析 --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jdepend-maven-plugin</artifactId> </plugin> <!-- PMD 代码分析 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>2.5</version> <configuration> <charset>utf-8</charset> <outputEncoding>utf-8</outputEncoding> <rulesets> <ruleset>/rulesets/basic.xml</ruleset> </rulesets> <format>xml</format> <linkXref>true</linkXref> <sourceEncoding>utf-8</sourceEncoding> <minimumTokens>100</minimumTokens> <targetJdk>1.5</targetJdk> </configuration> </plugin>