在使用Gradle在名为“Sample Project”的示例Android应用程序上运行sonarRunner任务时遇到问题。
我在mt build.gradle脚本中有以下配置:
apply plugin: "sonar-runner"
sonarRunner {
sonarProperties {
property "sonar.host.url", "http://localhost:9000/"
property "sonar.jdbc.url", "jdbc:h2:tcp://localhost:9092/sonar"
property "sonar.jdbc.driverClassName", "org.h2.Driver"
property "sonar.jdbc.username", "sonar"
property "sonar.jdbc.password", "sonar"
property "sonar.language", "java"
property "sonar.sources", "src/main/java"
property "sonar.test", "src/test/java"
property "sonar.binaries", "build"
}
}
所以当我跑:
gradle sonarRunner
我明白了:
* What went wrong:
Execution failed for task ':Sample Project:sonarRunner'.
> java.lang.IllegalArgumentException
使用命令:
gradle sonarRunner --stacktrace
我得到了:
.
.
.
Caused by: java.net.URISyntaxException: Illegal character in query at index 89: http://localhost:9000/batch_bootstrap/properties?project=com.company.demo.gradle:Sample Project&dryRun=false
答案 0 :(得分:0)
查看堆栈跟踪我注意到问题是因为插件使用的URL空间很大:
http://localhost:9000/batch_bootstrap/properties?project=com.company.demo.gradle:Sample Project&dryRun=false
要解决此问题,我在build.gradle脚本中添加了另一个属性:
property "sonar.projectKey", "standard-project-layout:sample-project"
这解决了我的问题,所以现在我的build.gradle脚本的配置如下所示:
apply plugin: "sonar-runner"
sonarRunner {
sonarProperties {
property "sonar.host.url", "http://localhost:9000/"
property "sonar.jdbc.url", "jdbc:h2:tcp://localhost:9092/sonar"
property "sonar.jdbc.driverClassName", "org.h2.Driver"
property "sonar.jdbc.username", "sonar"
property "sonar.jdbc.password", "sonar"
property "sonar.language", "java"
property "sonar.sources", "src/main/java"
property "sonar.test", "src/test/java"
property "sonar.binaries", "build"
// There is a problem when using "standard-project-layout:Sample Project" (by default)
// because of the wide space
property "sonar.projectKey", "standard-project-layout:sample-project"
}
}