今天无意中执行了一个gradle cleanEclipse任务,导致我的项目变成了普通的Java项目:
Gradle Dependence没有了,然后右击build.gradle->Run As也没有Gradle选项了:
项目右击->Config->Convert to Gradle Project
Gradle项目自身自带一个Gradle dependencies依赖库,有时我们自己添加的jar包可能会产生一个依赖库,这两个依赖库如何合并?
在执行gradle sonarRunner
命令时,会出现如下错误:
:sonarRunner
SonarQube Runner 2.3
Java 1.7.0_79 Oracle Corporation (64-bit)
Mac OS X 10.10.3 x86_64
INFO: Runner configuration file: NONE
INFO: Project configuration file: /Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/build/tmp/sonarRunner/sonar-project.properties
INFO: Default locale: "zh_CN", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Work directory: /Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/build/sonar
INFO: SonarQube Server 4.5.4
18:42:01.507 INFO - Load global referentials...
18:42:01.771 INFO - Load global referentials done: 266 ms
18:42:01.780 INFO - User cache: /Users/wuxian/.sonar/cache
18:42:01.791 INFO - Install plugins
18:42:01.944 INFO - Install JDBC driver
18:42:01.954 INFO - Create JDBC datasource for jdbc:mysql://10.58.37.253:3306/sonar
18:42:03.486 INFO - Initializing Hibernate
18:42:05.145 INFO - Load project referentials...
18:42:05.304 INFO - Load project referentials done: 159 ms
18:42:05.305 INFO - Load project settings
18:42:05.650 INFO - Loading technical debt model...
18:42:05.676 INFO - Loading technical debt model done: 26 ms
18:42:05.678 INFO - Apply project exclusions
18:42:05.849 WARN - 'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used.
18:42:06.080 INFO - ------------- Scan ResponseTimeTool
18:42:06.086 INFO - Load module settings
18:42:07.026 WARN - sonar.binaries and sonar.libraries are deprecated since version 2.5 of sonar-java-plugin, please use sonar.java.binaries and sonar.java.libraries instead
18:42:07.028 INFO - Loading rules...
18:42:07.739 INFO - Loading rules done: 711 ms
18:42:07.763 INFO - Configure Maven plugins
18:42:07.879 INFO - No quality gate is configured.
18:42:08.036 INFO - Base dir: /Users/wuxian/Documents/sourcecode/self/ResponseTimeTool
18:42:08.036 INFO - Working dir: /Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/build/sonar
18:42:08.037 INFO - Source paths: src/main/resources, src/main/java
18:42:08.037 INFO - Test paths: src/test/resources, src/test/java
18:42:08.037 INFO - Binary dirs: build/classes/main, build/resources/main
18:42:08.037 INFO - Source encoding: UTF-8, default locale: zh_CN
18:42:08.037 INFO - Index files
18:42:08.324 INFO - 7 files indexed
18:42:08.709 INFO - Quality profile for java: Android Lint
18:42:08.733 INFO - Sensor JavaSquidSensor...
18:42:09.198 INFO - Java Main Files AST scan...
18:42:09.201 INFO - 6 source files to be analyzed
18:42:09.654 INFO - Java Main Files AST scan done: 456 ms
18:42:09.654 INFO - 6/6 source files analyzed
18:42:09.656 INFO - Java bytecode scan...
18:42:09.692 INFO - Java bytecode scan done: 36 ms
18:42:09.692 INFO - Java Test Files AST scan...
18:42:09.692 INFO - 1 source files to be analyzed
18:42:09.709 INFO - Java Test Files AST scan done: 17 ms
18:42:09.709 INFO - 1/1 source files analyzed
18:42:09.712 INFO - Package design analysis...
18:42:09.755 INFO - Package design analysis done: 43 ms
18:42:09.760 INFO - Sensor JavaSquidSensor done: 1027 ms
18:42:09.769 INFO - Sensor QProfileSensor...
18:42:09.773 INFO - Sensor QProfileSensor done: 4 ms
18:42:09.773 INFO - Sensor InitialOpenIssuesSensor...
18:42:09.810 INFO - Sensor InitialOpenIssuesSensor done: 37 ms
18:42:09.810 INFO - Sensor ProjectLinksSensor...
18:42:09.824 INFO - Sensor ProjectLinksSensor done: 14 ms
18:42:09.831 INFO - Sensor VersionEventsSensor...
18:42:09.855 INFO - Sensor VersionEventsSensor done: 24 ms
18:42:09.855 INFO - Sensor FileHashSensor...
18:42:09.857 INFO - Sensor FileHashSensor done: 2 ms
18:42:09.857 INFO - Sensor SurefireSensor...
18:42:09.858 INFO - parsing /Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/build/test-results
18:42:09.956 INFO - Sensor SurefireSensor done: 99 ms
18:42:09.956 INFO - Sensor JaCoCoOverallSensor...
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 9.187s
Final Memory: 25M/538M
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
INFO: ------------------------------------------------------------------------
ERROR: Caused by: Unable to read /Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/build/jacoco/test.exec
ERROR: Caused by: Incompatible version 1007.
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
:sonarRunner FAILED
无法解析test.exec文件
出现上述问题的原因是因为jacoco自身的问题,造成和sonarrunner不兼容,我们将jacoco的版本降到如下版本就没问题了:
jacoco{
toolVersion = "0.7.4.201502262128"
reportsDir = file("$buildDir/jacocoReport")
}
我们用SonarRunner分析完数据后,在SonarQube网页中查看源码时发现中文变乱码,这个问题如何解决?
首先要确保你的各种encode保持为UTF-8,比如编辑器是否为UTF-8,property "sonar.sourceEncoding", "UTF-8"
是否为UTF-8,当这些问题都解决不了的时候,修改你的"sonar.jdbc.url"
属性:
sonarRunner {
sonarProperties {
property "sonar.host.url", "http://10.58.37.253:9000/"
property "sonar.jdbc.url", "jdbc:mysql://10.58.37.253: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.login", "admin"
property "sonar.password", "admin"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.profile", "Sonar way"
}
}
比一般的配置多了一个?useUnicode=true&characterEncoding=utf8
,这个加上后,乱码就解决了。