我有一个问题,设置与声纳和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 - <- Clean snapshot 127
BUILD SUCCESSFUL
Total time: 14.253 secs
22:36:45: External task execution finished 'sonarRunner'.
之后,在我的声纳中,我可以看到所有指标,但不能看到代码覆盖率。 你知道这里发生了什么吗?
答案 0 :(得分:3)
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?
未生成测试信息并将其保存到您指定的文件${buildDir}/jacoco/test.exec
,您已指定属性
property 'sonar.jacoco.reportPath', "${buildDir}/jacoco/test.exec"
但是如果要指定该属性
,则需要设置sonar.core.codeCoveragePlugin=jacoco
如果您打算这样做,您需要设置gradle以使用jacoco插件,请查看
Jacoco Plugin并正确配置,问题的相关部分是destinationFile = file("${buildDir}/jacoco/test.exec")
,然后使用gradle运行构建/测试过程并生成测试信息,这样您就可以运行声纳分析并找到它这个测试信息
答案 1 :(得分:0)
从现在开始,我认为您需要独立制作覆盖文件并将这些文件导入声纳。
对于C#代码,我们需要这样做。对于java项目,我不完全确定,但可能是一个原因。
您可以浏览此链接以获取有关C#覆盖范围更改的更多信息:http://docs.codehaus.org/display/SONAR/C%23+Plugin