Sonarqube css扫描问题

Posted

技术标签:

【中文标题】Sonarqube css扫描问题【英文标题】:Sonarqube css scan issue 【发布时间】:2018-07-04 08:39:01 【问题描述】:

我有 sonaqube 服务器和单独的 teamcity 服务器,我在 teamcity 配置中添加了一个步骤,以便在我的 css 代码存储库(在 bitbucket 中)上运行 sonar runner。

Sonarqube 服务器 - Sonarqube 6.7

添加插件 - sonarqube-6.7\extensions\plugins\sonar-css-plugin-4.13

我遇到了与 .css 文件上的声纳扫描相关的问题:

ERROR: Error during Sonar runner execution org.sonar.runner.impl.RunnerException: Unable to execute Sonar Caused by: org.sonar.squidbridge.api.AnalysisException: Unable to analyze file: E:/LocalAgent2/work/fe98ca8c22f54520/SourceCode/UI Design/Source/src/css/components.css
...
Caused by: org.sonar.squidbridge.api.AnalysisException: Unable to analyze file: E:/LocalAgent2/work/fe98ca8c22f54520/SourceCode/UI       Design/Source/src/css/components.css
...
Caused by: java.lang.IllegalArgumentException: 17 is not a valid line offset for pointer. File css/components.css has 16 character(s) at line 351

我已将 .css 文件的格式从 UTF-8 更新为 UTF-8 BOM,然后此问题消失但出现解析错误问题。那就无法解析了,请帮忙。

ERROR - Unable to parse file: E:/LocalAgent4/work/fe98ca8c22f54520/SourceCode/UI Design/Source/src/css/components.css ERROR - Parse error at line 1 column 2:
...
Caused by: java.lang.IllegalArgumentException: 17 is not a valid line offset for pointer. File css/components.css has 16 character(s) at line 351

【问题讨论】:

我们可以看看你的 CSS 吗?特别是第 351 行。 已解决:实际问题是 UTF-8 编码。 【参考方案1】:
Resloved: Actual issue was UTF-8 encoding. I tried to run scanner on actual code via cmd prompt with all required parameters available inside "sonar-project.properties" file. 

sonar.projectKey=simple-css-scss-less-project
sonar.projectName=Simple CSS / SCSS / Less Project
sonar.projectVersion=1.0
sonar.sources=src
sonar.sourceEncoding=UTF-8

And it was working fine, i am able to see scanned output inside sonar dashboard.

Then I have updated TeamCity configuration. Added build step with Sonar Runner and provided below mentioned parameters.
Project name:
Project key:
Project version:%build.number%
Most important part which resolved my issue --> Additional parameter section i have to add below line.

-Dsonar.sourceEncoding=UTF-8

【讨论】:

以上是关于Sonarqube css扫描问题的主要内容,如果未能解决你的问题,请参考以下文章

詹金斯 - sonarQube 问题 ||声纳扫描仪插件

Jenkins 使用 SonarQube 扫描 Coding

Sonarqube 扫描错误,行超出范围?

Sonarqube 扫描仪错误 DirectoryNotEmptyException

Sonarqube 与声纳扫描仪

SonarQube Runner 与扫描仪