我正在尝试排除一个目录从声纳分析。我在我的声纳项目中定义了以下属性。属性文件:
sonar.sources=src/java
sonar.exclusions=src/java/test/****/*.java
我的目录结构是:
src/java/dig
src/java/test/dig
当我运行声纳运行,我得到以下信息:
INFO - Excluded sources:
INFO - src/java/test/**/*.java
INFO - Excluded tests:
INFO - **/package-info.java
但是当我检查分析结果时,测试目录中的所有包仍然存在。
我只需要告诉声纳不要分析测试目录和它里面的任何包。
如果你是一个Azure DevOps用户,正在寻找在哪里以及如何排除文件和文件夹,这里你可以去:
Edit your pipeline
Make sure you have the "Prepare analysis on SonarQube" task added. You'll need to look elsewhere if you need help configuring this. Suggestion: Use the UI pipeline editor vs the yaml editor if you are missing the manage link. At present, there is no way to convert to UI from yaml. Just recreate the pipeline. If using git, you can delete the yaml from the root of your repo.
Under the 'Advanced' section of the "Prepare analysis on SonarQube" task, you can add exclusions. See advice given by others for specific exclusion formats.
例子:
# Additional properties that will be passed to the scanner,
# Put one key=value per line, example:
# sonar.exclusions=**/*.bin
sonar.exclusions=MyProjectName/MyWebContentFolder/**
注意:如果你不确定路径,你可以进入sonarqube,查看你的项目,查看所有或新的“Code Smells”,你需要的路径在每个问题组上面列出。你可以获取一个文件的完整路径,或者像下面这样使用野字符:
MyProjectName / MyCodeFile cs
MyProjectName / * *
如果你没有添加“运行代码分析”任务,那么就把它放在“构建解决方案**/*”之后的某个地方。sln的任务。
保存并排队,然后检查sonarqube服务器,看看排除是否有效。