如何解决Jenkins sonarscanner 显示结束警告
我刚刚部署了一个基于 jenkins 和 sonarqube 的 CI 系统。一旦 Jenkins Sonnarscanner 开始他的管道部分,我可以看到很多消息,如下所示:
WARN: Invalid character encountered in file /var/jenkins_home/workspace/Pipeline Test/code/..../CodigoSitioDAO.java at line 3 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.
好吧,我的 sonarqube 呼叫线路是:
sh "${scannerHome}/bin/sonar-scanner \
-Dsonar.sourceEnconding=UTF-8 \
-Dsonar.projectKey=My_Project\
-Dsonar.sources=. \
-Dsonar.java.binaries=. \
-Dsonar.nodejs.executable=. \
-Dsonar.login=c9bb378b2380af844c7465424933b942d10f5d18 \
-Dsonar.host.url=http://sonarqube:9000"
}
因此,一旦我检查了提到的文件,我在第 3 行看到的内容与警告消息无关:import java.sql.Connection;
还配置了-Dsonar.sourceEncoding=UTF-8
,我不得不说我不知道发生了什么。
你们中有人能帮我吗?
解决方法
在我看来,该文件不是 UTF-8。很可能(特别是如果您使用 Windows 编辑器)文件以某种特定于平台的编码保存,并且其内容对 UTF-8 没有意义。考虑以下几点:
Clase de implementación del DAO de los códigos
相同的内容已保存为 ANSI 和 UTF-8(保存时显式选择)。现在如果你比较字节内容,它们是不一样的:
$ hexdump -C test-ansi.txt
00000000 43 6c 61 73 65 20 64 65 20 69 6d 70 6c 65 6d 65 |Clase de impleme|
00000010 6e 74 61 63 69 f3 6e 20 64 65 6c 20 44 41 4f 20 |ntaci.n del DAO |
00000020 64 65 20 6c 6f 73 20 63 f3 64 69 67 6f 73 |de los c.digos|
0000002e
$ hexdump -C test-utf8.txt
00000000 43 6c 61 73 65 20 64 65 20 69 6d 70 6c 65 6d 65 |Clase de impleme|
00000010 6e 74 61 63 69 c3 b3 6e 20 64 65 6c 20 44 41 4f |ntaci..n del DAO|
00000020 20 64 65 20 6c 6f 73 20 63 c3 b3 64 69 67 6f 73 | de los c..digos|
00000030
请注意,相同的字符 ó
在 ANSI 中编码为 f3
,在 UTF-8 中编码为 c3 b3
。我相信这就是您的消息的内容:声明的编码是 UTF-8(可能是默认值),但字符内容 f3
在此编码下无效。请使用十六进制编辑器仔细检查您的编码。
附注:如果您直接从文件中复制并粘贴了您的行,请注意 Stack Overflow 也无法对其进行解码,确认它不是 UTF-8 编码的。 >
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。