SonarQube Exclude a directory

2019-03-09 14:48发布

I am trying to exclude a directory from being analyzed by Sonar. I have the following properties defined in my sonar-project.properties file:

sonar.sources=src/java
sonar.exclusions=src/java/test/****/*.java

The directory structure I have is:

src/java/dig
src/java/test/dig

When I run the sonar-runner I get the following info:

 INFO  - Excluded sources:
 INFO  -   src/java/test/**/*.java
 INFO  - Excluded tests:
 INFO  -   **/package-info.java

But when I check the result of the analysis all the packages inside the test directory are still there.

I just need to tell Sonar to not analyze the test directory and any packages inside it.

8条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-03-09 15:19

Another configuration option is adding a maven properties sonar.exclusions. Below is a sample pom file with exclusions of static jquery directory and static pdf viewer directory.

<project >
<modelVersion>4.0.0</modelVersion>
<artifactId>my Artifact</artifactId>
<!-- Enviroment variables can be referenced as such: ${env.PATH} -->
<packaging>war</packaging>
<url>http://maven.apache.org</url>

<properties>

    <junit.version>4.9</junit.version>
    <mockito.version>1.9.5</mockito.version>
    <jackson.version>1.9.7</jackson.version>
    <powermock.version>1.5</powermock.version>

    <!--Exclude the files Here-->
    <sonar.exclusions>src/main/webapp/static/jquery_ui/*,src/main/webapp/static/pdf-viewer/*,src/main/webapp/static/pdf-viewer/**,src/main/webapp/static/pdf-viewer/**/*</sonar.exclusions>
</properties>

查看更多
女痞
3楼-- · 2019-03-09 15:23

Try something like this:

sonar.exclusions=src/java/test/**
查看更多
该账号已被封号
4楼-- · 2019-03-09 15:24

If we want to skip the entire folder following can be used:

sonar.exclusions=folderName/**/*

And if we have only one particular file just give the complete path.

All the folder which needs to be exclude and be appended here.

查看更多
在下西门庆
5楼-- · 2019-03-09 15:31

I able to exclude multiple directories using the below config(comma separated folder paths)

sonar.exclusions=system/**, test/**, application/third_party/**, application/logs/**

And while running the sonar runner I got the following in the log

Excluded sources: 
  system/**
  test/**
  application/third_party/**
  application/logs/**
查看更多
别忘想泡老子
6楼-- · 2019-03-09 15:31

Just to mention that once you excluded the files from Sonar, do the same for Jacoco plugin:

<configuration>
<excludes>     
<exclude>com/acme/model/persistence/entity/TransactionEntity*</exclude>
<exclude>com/acme/model/persistence/ModelConstants.class</exclude>
</excludes>
</configuration> 
查看更多
你好瞎i
7楼-- · 2019-03-09 15:32

This will work for your case:

sonar.exclusions=**/src/java/dig/ ** , **/src/java/test/dig/ **
查看更多
登录 后发表回答