現象說明
maven的java項目,測試用例和main所在的源碼文件均符合缺省寫法和格式,但是在使用mvn clean sonar:sonar進行編譯時提示can't be indexed twice錯誤。
相關版本
使用如下相關版本信息:
錯誤信息提示
1
|
ERROR: Caused by: File [...] can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files |
相關信息說明
maven的pom中對于源碼和測試代碼的指定可以通過如下設定進行:
- <sourceDirectory>源碼目錄</sourceDirectory>
- <testSourceDirectory>測試代碼目錄<testSourceDirectory>
sonar中對于源碼目錄和測試代碼目錄的設定可以通過如下方式進行:
- sonar.sources=源碼目錄
- sonar.tests=測試代碼目錄
對策
可以通過設定sonar的exclusion/inclusion屬性來解決問題。通過-D傳入如下信息即可解決(例):
1
2
3
4
|
sonar.sources=. sonar.tests=. sonar.test.inclusions=** /*Test*/** sonar.exclusions=**/*Test*/ ** |
參考內容
https://github.com/SonarOpenCommunity/sonar-cxx/wiki/FAQ
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對服務器之家的支持。如果你想了解更多相關內容請查看下面相關鏈接
原文鏈接:https://blog.csdn.net/liumiaocn/article/details/85063738