Buscar este blog

domingo, 23 de octubre de 2016

Jenkins - SonarQube - Exclude sources from code analysis

If you need to exclude some folders from SONAR code analysis, for example, style sheets or javascript files, there are two options:
  • Set exclusions in the POM.XML file.
  • Set exclusions in the SONAR Runner plugin, in Jenkins.
In both cases, the key properties are (check http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus):
Use exclusion to analyze everything but the specified files:
  • sonar.exclusions - to exclude source code files
  • sonar.test.exclusions - to exclude unit test files
Use inclusion to analyzes only the specified files:
  • sonar.inclusions 
  • sonar.test.inclusions


For example, in POM.XML:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 (...)
 
 <properties>
  (...)  
        <sonar.exclusions>**/*.css,**/*.js</sonar.exclusions>      
 </properties>
 
</project>


In Jenkins, you can configure the SONAR plugin inside each job. In the Post-build Action you can set this configuration in the "Aditional properties" fields with "-D" prefix.


When the job runs, in the output console you will see something like this:
[INFO] [15:20:44.174] Source paths: src/main/webapp, pom.xml, src/main/java
[INFO] [15:20:44.175] Test paths: src/test/java
[INFO] [15:20:44.175] Binary dirs: target/classes
[INFO] [15:20:44.176] Source encoding: UTF-8, default locale: en_US
[INFO] [15:20:44.176] Index files
[INFO] [15:20:44.194] Excluded sources: 
[INFO] [15:20:44.194]   **/*.css
[INFO] [15:20:44.194]   **/*.js
[INFO] [15:20:47.235] 366 files indexed

No hay comentarios:

Publicar un comentario