上传到Soanr时,项目有单元测试数,但是覆盖率为0

修改pom.xml

                <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>false</skipTests>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<!--<exclude>**/Abstract*.java</exclude>-->
<!--<exclude>**/*Service.java</exclude>-->
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>pre-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>

必要时带上参数

clean cobertura:cobertura -Dcobertura.report.format=xml package -Dmaven.test.failure.ignore=true sonar:sonar -Dsonar.language=java

多模块项目通过Jenkins构建扫描上传到Sonar时,代码覆盖率很低,只覆盖了单模块的代码,这时可以通过配置JaCoCo解决该问题。

参考资料

修改pom.xml

            <plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

通过clean org.jacoco:jacoco-maven-plugin:prepare-agent jacoco:report-aggregate install 可在target下生成jacoco-aggregate覆盖相关报告

注:jacoco版本低于0.7.9 jacoco:report-aggregate参数可能不存在

多模块项目整合覆盖率还可以指定report目录

 <properties>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
</properties> <build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

【Java】 Maven多模块项目上传到Sonar扫描问题合集的更多相关文章

  1. eclipse导入SVN上的Maven多模块项目

    eclipse导入SVN上的Maven多模块项目 博客分类: Eclipse&MyEclipse SVN Maven   一.SVN上Maven多模块项目结构 使用eclipse导入SVN上的 ...

  2. Myeclipse10.7安装git插件并将Java项目上传到码云(github)

    注:本文来源:外匹夫的<Myeclipse10.7安装git插件并将Java项目上传到码云(github)> 一.先说说安装egit插件的步骤(安装egit不成功的原因主要是下载的egit ...

  3. 使用git将本地java项目上传到GitHub

    使用git将项目上传到github(最简单方法) 声明:本人是根据上文给的链接的方式,上传到github上的,亲测有效. 首先你需要一个github账号,所有还没有的话先去注册吧! https://g ...

  4. SpringBoot+Maven多模块项目(创建、依赖、打包可执行jar包部署测试)完整流程

    一,创建Maven多模块项目先建立外层父工程         File →new →project  选择Spring Initializr          Next下一步到以下页面 工程结构如下 ...

  5. 「 从0到1学习微服务SpringCloud 」09 补充篇-maven父子模块项目

    系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」06 统一配置中心Spring Cloud Config 「 从0到1学习微服务SpringCloud 」07 RabbitM ...

  6. Maven入门,Maven项目的创建,nexus 2.x搭建私服以及Maven多模块项目创建

    maven的了解做一个总结,以便日后查阅, 若有不足之处,还望指出,学无止境 当然也能起到入门效果. 一,搭建maven私服 1.工具 a. Nexus 2.5.1-01 b. Maven 3.3.9 ...

  7. 使用IDEA的项目上传到GitHub

    使用IDEA的项目上传到GitHub 前提条件: 1.配置好Git(https://jingyan.baidu.com/article/8275fc867b652046a03cf613.html) 2 ...

  8. Spring Boot 项目实战(一)Maven 多模块项目搭建

    一.前言 最近公司项目准备开始重构,框架选定为 Spring Boot ,本篇主要记录了在 IDEA 中搭建 Spring Boot Maven 多模块项目的过程. 二.软件及硬件环境 macOS S ...

  9. 导入maven多模块项目 出现的问题

    近日导入maven多模块项目 出现的问题以及解决过程2017年12月04日 20:43:04 守望dfdfdf 阅读数:815 标签: jdkmavenmaven pom.xml 更多个人分类: 工作 ...

随机推荐

  1. 重学JAVA基础(三):动态代理

    1.接口 public interface Hello { public void sayHello(); } 2.实例类 public class Hello2 { public void sayH ...

  2. RDA项目打包

    注意APP的编译搭建: ./aps/Makefile.toolchain //ccoption path的设定 ./aps/rules.mak //统一的编译规则 MAKE -C 1.TOOLS的可执 ...

  3. ng2中的ng-content用法

    用途:1.ng-content用于在组件中嵌入内容 2.ng-content可以在组件中嵌入模板代码,方便定制可复用的组件 select属性支持css选择器,如"#id",&quo ...

  4. java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport

    转自:https://blog.csdn.net/lzx159951/article/details/79753493 1. 缺少:org.springframework.transaction-3. ...

  5. JavaScript 数据访问(通译自High Performance Javascript 第二章) [转]

    JavaScript 数据访问(通译自High Performance Javascript 第二章)   JavaScript 数据访问(翻译自High Performance Javascript ...

  6. HDU - 1078 FatMouse and Cheese(记忆化+dfs)

    FatMouse and Cheese FatMouse has stored some cheese in a city. The city can be considered as a squar ...

  7. 核心容器的两个接口(ApplicationContext和BeanFactory)引发出的问题

    BeanFactory 才是Spring 容器中的顶层接口.ApplicationContext 是它的子接口. ApplicationContext 它在构建核心容器时, 创建对象采取的策略是采用立 ...

  8. Vue Study [1]: Vue Setup

    Description The article for vue.js Setup. Original post link:https://www.cnblogs.com/markjiang7m2/p/ ...

  9. keycode和which

    firefox 中不支持keyCode ie9-- 不支持which firefox:上下左右键会触发kepress. chrome: 上下左右键不会触发kepress. oprea:上下左右键不会触 ...

  10. c# 库间关系