sonar提高Java实体类覆盖率_java-SonarQube不收集代码覆盖率

在使用SonarQube和JaCoCo进行Java项目分析时,发现SonarQube未显示代码覆盖率。配置Gradle构建文件并运行sonarRunner任务后,控制台显示Jacoco报告路径正确,但SonarQube仍无法收集到覆盖率数据。解决方案可能是手动创建覆盖率文件并导入SonarQube,尽管通常这个过程是自动化的。

我在与声纳运行器和jacoco设置gradle时遇到问题.除了代码覆盖范围之外,一切都很好.我已经尝试了所有没有结果的东西.

这是我的build.gradle文件:

apply from: './dependencies.gradle'

def langLevel = 1.8

allprojects {

apply plugin: 'idea'

apply plugin: 'eclipse'

group 'pl.lodz.uml.sonda'

version '1.0.0'

}

subprojects {

apply plugin: 'java'

apply plugin: 'sonar-runner'

apply plugin: 'jacoco'

compileJava.options.encoding = 'UTF-8'

sourceCompatibility = langLevel

targetCompatibility = langLevel

repositories {

mavenLocal()

mavenCentral()

}

jacoco {

toolVersion = "0.7.0.201403182114"

}

sonarRunner {

sonarProperties {

property 'sonar.host.url', 'http://localhost:9000'

property 'sonar.login', 'admin'

property 'sonar.password', 'admin'

property 'sonar.jdbc.url', 'jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8'

property 'sonar.jdbc.driverClassName', 'com.mysql.jdbc.Driver'

property 'sonar.jdbc.username', 'sonar'

property 'sonar.jdbc.password', 'sonar'

property 'sonar.jacoco.reportPath', "${buildDir}/jacoco/test.exec"

property 'sonar.junit.reportsPath', "${buildDir}/test-results"

}

}

dependencies {

compile deps.spring.context

testCompile deps.test

}

}

project(':sonda-uml-common') {

dependencies {

}

}

project(':sonda-uml-integration') {

dependencies {

compile deps.spring.web

compile deps.javax.servlet

}

}

当我运行sonarRunner任务时,这是控制台的输出:

22:36:31: Executing external task 'sonarRunner'...

:sonda-uml-integration:compileJava

:sonda-uml-integration:processResources

:sonda-uml-integration:classes

:sonda-uml-integration:compileTestJava

:sonda-uml-integration:processTestResources UP-TO-DATE

:sonda-uml-integration:testClasses

:sonda-uml-integration:test

:sonda-uml-integration:sonarRunner

22:36:37.780 INFO - Load batch settings

22:36:37.911 INFO - User cache: C:\Users\Piotr\.sonar\cache

22:36:37.919 INFO - Install plugins

22:36:38.003 INFO - Install JDBC driver

22:36:38.013 INFO - Create JDBC datasource for jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8

22:36:38.954 INFO - Initializing Hibernate

22:36:41.073 INFO - Load project settings

22:36:41.123 INFO - Apply project exclusions

22:36:41.157 WARN - 'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used.

22:36:41.312 INFO - ------------- Scan sonda-uml-integration

22:36:41.317 INFO - Load module settings

22:36:41.710 INFO - Loading technical debt model...

22:36:41.718 INFO - Loading technical debt model done: 8 ms

22:36:41.718 INFO - Loading rules...

22:36:42.080 INFO - Loading rules done: 362 ms

22:36:42.095 INFO - Configure Maven plugins

22:36:42.148 INFO - Compare to previous analysis (2014-06-28)

22:36:42.153 INFO - Compare over 30 days (2014-05-29, analysis of 2014-06-28 19:27:48.0)

22:36:42.154 INFO - No quality gate is configured.

22:36:42.277 INFO - Base dir: D:\projects\sonda-uml\sonda-uml-integration

22:36:42.277 INFO - Working dir: D:\projects\sonda-uml\sonda-uml-integration\build\sonar

22:36:42.277 INFO - Source dirs: D:\projects\sonda-uml\sonda-uml-integration\src\main\resources, D:\projects\sonda-uml\sonda-uml-integration\src\main\java

22:36:42.278 INFO - Test dirs: D:\projects\sonda-uml\sonda-uml-integration\src\test\resources, D:\projects\sonda-uml\sonda-uml-integration\src\test\java

22:36:42.279 INFO - Binary dirs: D:\projects\sonda-uml\sonda-uml-integration\build\classes\main, D:\projects\sonda-uml\sonda-uml-integration\build\resources\main

22:36:42.279 INFO - Source encoding: windows-1250, default locale: pl_PL

22:36:42.279 INFO - Index files

22:36:42.341 INFO - 5 files indexed

22:36:42.962 INFO - Quality profile for java: Sonar way

22:36:42.974 INFO - Sensor JavaSquidSensor...

22:36:43.022 INFO - Java Main Files AST scan...

22:36:43.027 INFO - 4 source files to be analyzed

22:36:43.628 INFO - 4/4 source files analyzed

22:36:43.630 INFO - Java Main Files AST scan done: 608 ms

22:36:43.634 INFO - Java bytecode scan...

22:36:43.679 INFO - Java bytecode scan done: 45 ms

22:36:43.680 INFO - Java Test Files AST scan...

22:36:43.680 INFO - 1 source files to be analyzed

22:36:43.683 INFO - Java Test Files AST scan done: 3 ms

22:36:43.686 INFO - 1/1 source files analyzed

22:36:43.690 INFO - Package design analysis...

22:36:43.741 INFO - Package design analysis done: 51 ms

22:36:43.795 INFO - Sensor JavaSquidSensor done: 821 ms

22:36:43.796 INFO - Sensor QProfileSensor...

22:36:43.828 INFO - Sensor QProfileSensor done: 32 ms

22:36:43.829 INFO - Sensor InitialOpenIssuesSensor...

22:36:43.840 INFO - Sensor InitialOpenIssuesSensor done: 11 ms

22:36:43.841 INFO - Sensor ProfileEventsSensor...

22:36:43.859 INFO - Sensor ProfileEventsSensor done: 18 ms

22:36:43.859 INFO - Sensor ProjectLinksSensor...

22:36:43.864 INFO - Sensor ProjectLinksSensor done: 5 ms

22:36:43.864 INFO - Sensor VersionEventsSensor...

22:36:43.941 INFO - Sensor VersionEventsSensor done: 77 ms

22:36:43.941 INFO - Sensor FileHashSensor...

22:36:43.942 INFO - Sensor FileHashSensor done: 1 ms

22:36:43.942 INFO - Sensor CpdSensor...

22:36:43.943 INFO - SonarEngine is used for java

22:36:43.944 INFO - Cross-project analysis disabled

22:36:43.963 INFO - Sensor CpdSensor done: 21 ms

22:36:43.964 INFO - Sensor SurefireSensor...

22:36:43.964 INFO - parsing D:\projects\sonda-uml\sonda-uml-integration\build\test-results

22:36:44.021 INFO - Sensor SurefireSensor done: 57 ms

22:36:44.021 INFO - Sensor JaCoCoSensor...

22:36:44.024 INFO - Analysing D:\projects\sonda-uml\sonda-uml-integration\build\jacoco\test.exec

22:36:44.043 WARN - Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?

22:36:44.043 INFO - Sensor JaCoCoSensor done: 22 ms

22:36:44.341 INFO - Execute decorators...

22:36:44.884 INFO - Store results in database

22:36:45.051 INFO - ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/pl.lodz.uml.sonda:sonda-uml-integration

22:36:45.161 INFO - Executing post-job class org.sonar.plugins.core.issue.notification.SendIssueNotificationsPostJob

22:36:45.161 INFO - Executing post-job class org.sonar.plugins.core.batch.IndexProjectPostJob

22:36:45.218 INFO - Executing post-job class org.sonar.plugins.dbcleaner.ProjectPurgePostJob

22:36:45.225 INFO - -> Keep one snapshot per day between 2014-05-31 and 2014-06-27

22:36:45.226 INFO - -> Keep one snapshot per week between 2013-06-29 and 2014-05-31

22:36:45.226 INFO - -> Keep one snapshot per month between 2009-07-04 and 2013-06-29

22:36:45.227 INFO - -> Delete data prior to: 2009-07-04

22:36:45.231 INFO - -> Clean sonda-uml-integration [id=10]

22:36:45.234 INFO -

BUILD SUCCESSFUL

Total time: 14.253 secs

22:36:45: External task execution finished 'sonarRunner'.

之后,在声纳中,我可以看到所有指标,但看不到代码覆盖率.

你知道这里会发生什么吗?

解决方法:

从现在开始,我认为您需要独立制作覆盖文件并将这些文件导入声纳.

对于C#代码,我们需要这样做.对于Java项目,我不确定,但可能是一个原因.

标签:jacoco,sonarqube,gradle,java

来源: https://codeday.me/bug/20191121/2052743.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值