Java Sonarqube:缺少以下文件的责任信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37432290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 19:19:57  来源:igfitidea点击:

Sonarqube: Missing blame information for the following files

javagitmavenjenkinssonarqube

提问by Amedee Van Gasse

I am getting the warning Missing blame information for the following filesduring analysis by SonarQube.

Missing blame information for the following files在 SonarQube 分析期间收到警告。

[INFO] [22:19:57.714] Sensor SCM Sensor
[INFO] [22:19:57.715] SCM provider for this project is: git
[INFO] [22:19:57.715] 48 files to be analyzed
[INFO] [22:19:58.448] 0/48 files analyzed
[WARN] [22:19:58.448] Missing blame information for the following files:
(snip 48 lines)
[WARN] [22:19:58.449] This may lead to missing/broken features in SonarQube
[INFO] [22:19:58.449] Sensor SCM Sensor (done) | time=735ms

I am using SonarQube 5.5, analysis is done by Maven in a Jenkins job, on a multi-module Java project. Git plugin 1.2 is installed.

我正在使用 SonarQube 5.5,分析是由 Maven 在 Jenkins 工作中在多模块 Java 项目中完成的。安装了 Git 插件 1.2。

Manually running git blame in a bash shell, on any of the offending files, gives an expected output.

在 bash shell 中对任何有问题的文件手动运行 git blame 会给出预期的输出。

Related questions I found were all about SVN, my issue is with Git.

我发现的相关问题都是关于 SVN,我的问题是 Git。

How do I get git blame information on Sonarqube?

我如何获得关于 Sonarqube 的 git blame 信息?

采纳答案by Amedee Van Gasse

The cause was a JGit bug. JGit does not support .gitattributes. I had identin my .gitattributes. Plain console gitchecked out the source, applied identon $Id$macros, but then JGit ignored that and saw a difference that wasn't committed, where there actually wasn't one.

原因是JGit 错误。JGit 不支持.gitattributes. 我ident在我的.gitattributes. 平原控制台git签出的来源,适用ident$Id$宏,但随后JGit忽略了,看到没被提交的,那里居然没有一个差异。

The friendly people on the SonarQube mailing listhelped me out, and suggested debugging with the standalone JGit command line distribution:

SonarQube 邮件列表上的友好人士帮助了我,并建议使用独立的 JGit 命令行发行版进行调试:

chmod +x /where/is/org.eclipse.jgit.pgm-<version>-r.sh
/where/is/org.eclipse.jgit.pgm-<version>-r.sh blame -w /path/to/offending/file

This particular JGit bug has not been solved for over 5 years and I have no hope that it will be solved anytime soon, so I removed the $Id$macros from all my sources.

这个特殊的 JGit 错误已经超过 5 年没有解决了,我不希望它会很快得到解决,所以我$Id$从我的所有来源中删除了宏。

This is the (Bash) code I used, to remove all $Id$macros:

这是我用来删除所有$Id$宏的(Bash)代码:

find */src -name "*.java" | xargs -n 1 sed -i '/$Id.*$/d'
find */src -name "*.java" | xargs git add
git commit -m "Remove $Id$ macros"
git push

回答by John Meyer

I had a similar issue: a file in my project was created during the build process and was not stored in source control. In my case it was api.json.

我有一个类似的问题:我的项目中的一个文件是在构建过程中创建的,并且没有存储在源代码管理中。就我而言,它是api.json.

Within the SonarQube runner build step in Team City I added this file to the exclusions within the additional parameters

在 Team City 的 SonarQube runner 构建步骤中,我将此文件添加到附加参数中的排除项中

-Dsonar.exclusions=**/spec/api.json

and the error disappeared.

并且错误消失了。

回答by neoscribe

I ran into this issue with a build that stopped working after a Sonar upgrade.

我在声纳升级后停止工作的构建遇到了这个问题。

The problem for me was that the Jenkins job was configured to do a Shallow Clone when pulling from git. This does not pull in enough history so Sonar 5.6.6 could not do an analysis because blame information was not included in the shallow copy. I used the -Xoption when running Sonar to view the actual commit number that it was choking on.

我的问题是Jenkins 作业被配置为在从 git 拉取时执行浅克隆。这并没有引入足够的历史记录,因此 Sonar 5.6.6 无法进行分析,因为浅拷贝中未包含指责信息。我在运行 Sonar 时使用了-X选项来查看它阻塞的实际提交数。

I'm my case I simply unchecked the shallow copy check boxand BAM, it worked again (though more slowly)! enter image description here

我就是我的情况,我只是取消选中浅复制复选框和 BAM,它又工作了(虽然更慢)! 在此处输入图片说明