Java pom.xml(Maven 多模块项目)中的 <sonar.exclusions> 在本地工作,但不在公司服务器上工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25193563/
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-10 23:50:35  来源:igfitidea点击:

<sonar.exclusions> in pom.xml (Maven multi-module project) works locally but not on company server

javamavenjenkinssonarqube

提问by user3920253

I'm using <sonar.exclusions>in pom.xml to exclude certain packages for unit test code coverage. I have set up Sonar locally and the exclusions reflect on the report. But then, the same exclusions are not honored on the company server.

<sonar.exclusions>在 pom.xml 中使用以排除单元测试代码覆盖率的某些包。我在本地设置了声纳,排除项反映在报告中。但是,同样的排除在公司服务器上不受尊重。

I am using <sonar.skippedModules>which works as intended and skips the required modules perfectly fine on both environments.

我正在使用<sonar.skippedModules>它按预期工作并在两种环境中完美地跳过所需的模块。

Local Sonar version is Version 4.3.1 Company's Sonar version is Version 4.1.2

本地Sonar版本为4.3.1版本 公司Sonar版本为4.1.2版本

An example of how I have written <sonar.skippedModules>in one of the modules:

我如何<sonar.skippedModules>在其中一个模块中编写代码的示例:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.mainClass>.....</project.mainClass>
    <sonar.exclusions>
        /src/main/java/../../../../../Package1/*,
        /src/main/java/../../../../../Package2/*,
        /src/main/java/../../../../../JavaClass1.java
    </sonar.exclusions>
    <sonar.language>java</sonar.language>
</properties>

Can you please help me understand why <sonar.exclusions>is honored only locally but not when I build the job (set up on Jenkins) to generate the Sonar report on the company server? Does the difference in the version matter?

您能否帮助我理解为什么<sonar.exclusions>仅在本地获得荣誉,而在我构建作业(在 Jenkins 上设置)以在公司服务器上生成声纳报告时却没有获得荣誉?版本的差异重要吗?

Would absence of new-line character following the comma to separate the package names make a difference?

逗号后面没有换行符来分隔包名会有所不同吗?

采纳答案by Nirav Shah

Try this, I had same issue and it worked for me

试试这个,我有同样的问题,它对我有用

Don't start with "/src/main/java/" Instead start with "com/companyname/projectname/"

不要以“ /src/main/java/”开头,而是以“ com/companyname/projectname/”开头

I personally prefer "**com/companyname/projectname/../**"

我个人更喜欢“ **com/companyname/projectname/../**

回答by Mithfindel

I might be mistaken, but you should remove the /characters at the beginning of the sonar.exclusionspathes, to have them computed relative to the project's root directory.

我可能弄错了,但是您应该删除路径/开头的字符sonar.exclusions,以便相对于项目的根目录计算它们。