gpt4 book ai didi

gradle - 安卓 : run sonarRunner from gradle

转载 作者:行者123 更新时间:2023-12-04 15:57:37 25 4
gpt4 key购买 nike

我一直试图让 Sonar 报告与 gradle Android 项目一起运行。因为大多数重要的 Sonar 特性仅由 sonarRunner gradle plugin 应用。当项目是 java项目我无法将它们应用于 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?
}
}

问题是, Sonar 提示找不到类,因为无法引用库。

我的 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

最佳答案

我有一个适用于我的多项目 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() }
}
}
}

请注意
  • 我使用测试运行时类路径库,因为我们有一个providedCompile 范围,它不会在主运行时类路径中考虑。
  • 如果库设置包含不存在的目录(例如,因为模块没有 src/main/resources)
  • , Sonar 运行器会提示
  • sonar.java.libraries被使用,因为它不适用于 sonar.libraries为了我。
  • 关于gradle - 安卓 : run sonarRunner from gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25135589/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com