Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

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

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

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

<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?

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

like image 202
user3920253 Avatar asked Aug 07 '14 22:08

user3920253


People also ask

What is the difference between sonar coverage exclusions and sonar exclusions?

coverage. exclusions excludes some files from the test coverage metrics but those files are still analyzed: other metrics, duplications, coding rules... sonar. exclusions completely excludes some files from the analysis: those files don't appear at all in SonarQube.

How do I set sonar coverage exclusions?

To do so, go to Project Settings > General Settings > Analysis Scope > Code Coverage and set the Coverage Exclusions property. See the Patterns section for more details on the syntax.


1 Answers

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

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

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

like image 193
Nirav Shah Avatar answered Oct 16 '22 15:10

Nirav Shah