【发布时间】:2015-08-01 11:13:10
【问题描述】:
我正在使用 SonarQube 5.1 来收集 Android 应用的所有 Java 和 Lint 错误。
Sonar 使用 Lint 插件已经发现了几乎所有重要问题,但我发现至少有一个问题不包括在内:
<issue
id="GradleOverrides"
severity="Warning"
message="This `minSdkVersion` value (`14`) is not used; it is always overridden by the value specified in the Gradle build script (`15`)"
category="Correctness"
priority="4"
summary="Value overridden by Gradle build script"
explanation="The value of (for example) `minSdkVersion` is only used if it is not specified in the `build.gradle` build scripts. When specified in the Gradle build scripts, the manifest value is ignored and can be misleading, so should be removed to avoid ambiguity."
errorLine1=" <uses-sdk android:minSdkVersion="14" />"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="C:\Code\Android\TestApp\app\src\main\AndroidManifest.xml"
line="5"
column="15"/>
</issue>
此问题与AndroidManifest.xml(设置Android minSdkVersion 属性的传统方式)和build.gradle(设置minSdkVersion 元素的当前方式)有关。
我已经阅读了documentation about creating new rules in Sonar,但我是 仍然很困惑。我已经下载了SSLR for XML 并执行它来查找XPath 字符串。
我的 XML 文件是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.juanacaja.testapp" >
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
...寻找minSdkVersion 元素的XPath 是:
//manifest/uses-sdk/@android:minSdkVersion
我不确定我现在必须做什么。此外,SonarQube 5.1 Web 界面已更改,我看不到如何将 XPath 字符串添加到新规则中。
任何帮助将不胜感激!
【问题讨论】:
-
顺便说一句,SonarQube 文档的旧链接目前已损坏,例如:docs.codehaus.org/display/SONAR/Extending+Coding+Rules。 SonarSource 有人可以修复它吗?
-
是的,由于 CodeHaus 关闭,这是一个正在进行的过程 - 新 URL 是 docs.sonarqube.org/display/DEV/Extending+Coding+Rules
标签: java android xpath sonarqube lint