29

I have a sonar-project.properties file, which specifies how sonar-runner inspects the the folder structure, which files to inspect, which files to ignore etc.

I cannot successfully determine however how to exclude multiple paths successfully.

Here is the sonar-project.properties file:

sonar.projectKey=C3S-web
sonar.projectName=C3S-sonar-web
sonar.projectVersion=0.0.1

sonar.sources=.
sonar.tests=test
sonar.language=js
sonar.profile=Sonar way
sonar.exclusions=test/*, node_modules/*
sonar.dynamicAnalysis=reuseReports

sonar.javascript.jstest.reportsPath=coverage
sonar.javascript.lcov.reportPath=coverage/lcov-report

the line I am having trouble with is:

sonar.exclusions

listing multiple paths does not work, with or without a comma, or in quotes either.

Jon Duffy
  • 706
  • 1
  • 7
  • 15
  • Have you tried without a space? e.g ``sonar.exclusions=test/*,node_modules/*`` – Mithfindel Jun 10 '15 at 12:57
  • Yeah it still tries to index the .node_modules folder when I do that – Jon Duffy Jun 10 '15 at 12:58
  • as per this link http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus comma separated values should work. Can you try this: sonar.exclusions=**/test/*,* */node_modules/ * (ignore the spaces, those stars should be together, the editor was formatting it italics, don't know how to escape that :) – Techtwaddle Jun 10 '15 at 15:07
  • Cheers, for the link. That pattern still includes the node_modules folder though – Jon Duffy Jun 10 '15 at 15:51
  • Can you please put the analysis logs on pastebin.com so that we can take a look at what the analysis does? – Fabrice - SonarSource Team Jun 11 '15 at 12:58
  • Hey the logs in the terminal that come to the terminal whilst sonar-runner is running or are there other logs somewhere else? – Jon Duffy Jun 11 '15 at 13:47
  • Does this answer your question? [How to specify wildcards in sonar-project.properties](https://stackoverflow.com/questions/30929800/how-to-specify-wildcards-in-sonar-project-properties) – J.Wincewicz Nov 08 '21 at 13:42
  • @Techtwaddle your link has changed: (but i can't edit your comment) https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/ – Peter McIntyre Jun 19 '23 at 03:51

3 Answers3

39

You have to use the double asterisk pattern to recursively exclude all sub-folders and files:

sonar.exclusions=test/**, node_modules/**

A single asterisk matches only the files on that specific folder (no recursion).

Pedro Penna
  • 1,127
  • 1
  • 15
  • 24
4

Following will exclude all the files in node_modules, test.ts, all modules , main.ts and the files comes under environment folder

sonar.exclusions=**/node_modules/**,**/test.ts,**/environments/**,**/**module.ts,**/main.ts
Deepu Reghunath
  • 8,132
  • 2
  • 38
  • 47
0

If you are using Jenkinsfile

sonar: [ 

    sonarInstanceName: 'InstanceNameFolderProject', 
    sonarProperties: [
          'sonar.projectKey': 'C3S-web',
          'sonar.sources': 'yourFolderProject',
          'sonar.exclusions': 'yourFolderProject/**/*.fixture.ts, yourFolderProject/settings/_variables.ts' 
        ]],

In 'sonar.exclusions' you can exclude multiple paths.

Hamada
  • 1,836
  • 3
  • 13
  • 27