我一直试图让声纳报告与gradle Android项目一起运行。由于大多数重要的声纳属性仅在项目为java
项目时由sonarRunner gradle plugin应用,因此我无法将其应用于com.android.application
项目。
这是我的sonarRunner配置:
sonarRunner {
sonarProperties {
property "sonar.sourceEncoding", "UTF-8"
property "sonar.profile", "Android Lint"
property "sonar.sources", android.sourceSets.main.java.srcDirs
property "sonar.binaries", file("${project.buildDir}/intermediates/classes/app")
property "sonar.libraries", "" // what to put here?
}
}
问题是,声纳正在抱怨没有找到类,因为无法引用库。
如何在我的sonarRunner配置中引用依赖项+ android库?
示例错误输出:
INFO - Load batch settings
INFO - User cache: C:\Users\mannaz\.sonar\cache
INFO - Install plugins
INFO - Install JDBC driver
INFO - Create JDBC datasource for jdbc:postgresql://sonar.local/sonar?useUnicode=true&characterEncoding=utf8
INFO - Initializing Hibernate
INFO - Load project settings
INFO - Apply project exclusions
WARN - 'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used.
INFO - ------------- Scan app
INFO - Load module settings
INFO - Loading technical debt model...
INFO - Loading technical debt model done: 20 ms
INFO - Loading rules...
INFO - Loading rules done: 584 ms
INFO - Configure Maven plugins
INFO - Compare to previous analysis (2014-08-05)
INFO - Compare over 30 days (2014-07-06, analysis of 2014-07-07 11:33:19.0)
INFO - Compare to previous version (2014-07-21)
INFO - No quality gate is configured.
INFO - Base dir: C:\Users\mannaz\workspace\project\app
INFO - Working dir: C:\Users\mannaz\workspace\project\app\build\sonar
INFO - Source dirs: C:\Users\mannaz\workspace\project\app\src\main\java
INFO - Binary dirs: C:\Users\mannaz\workspace\project\app\build\intermediates\classes\app
INFO - Source encoding: UTF-8, default locale: de_AT
INFO - Index files
INFO - 197 files indexed
INFO - Quality profile for java: Android Lint
INFO - Sensor JavaSquidSensor...
INFO - Java Main Files AST scan...
INFO - 197 source files to be analyzed
ERROR - Class not found: android.widget.RelativeLayout
ERROR - Class not found: android.os.Handler
ERROR - Class not found: android.content.Context
ERROR - Class not found: android.app.Activity
ERROR - Class not found: android.util.AttributeSet
ERROR - Class not found: android.view.View
ERROR - Class not found: com.nostra13.universalimageloader.core.DisplayImageOptions
ERROR - Class not found: com.google.gson.Gson
答案 0 :(得分:1)
我有一个适用于我的多项目Gradle构建的解决方案:
subprojects.each { p ->
sonarRunner {
sonarProperties {
// ... some settings omitted ...
property p.name + '.sonar.java.binaries', p.sourceSets.main.output.classesDir
property p.name + '.sonar.java.libraries', p.sourceSets.test.runtimeClasspath.filter { File f -> f.exists() }
}
}
}
请注意
sonar.java.libraries
被使用,因为它不适用于sonar.libraries
。答案 1 :(得分:0)
我猜您只需要使用正确的配置手动设置库属性。像这样:
sonarRunner {
sonarProperties {
property "sonar.sourceEncoding", "UTF-8"
property "sonar.profile", "Android Lint"
property "sonar.sources", android.sourceSets.main.java.srcDirs
property "sonar.binaries", file("${project.buildDir}/intermediates/classes/app")
property "sonar.libraries", "android.sourceSets.main.runtimeClasspath"
}
}
或者你的正确依赖配置是正确的。