Code duplication exclusion list not working

  • ALM used: Bitbucket Cloud
  • CI system used: AWS CodeBuild
  • Scanner command used when applicable:
- sonar-scanner 
        -Dsonar.organization=myapp
        -Dsonar.projectKey=my_backend
        -Dsonar.sources=.
        -Dsonar.exclusions=./node_modules/**,**/__tests__/**,./index.js,./server/index.js,./database/**,./app/services/Firebase/exports/**
        -Dsonar.cpd.exclusions=./database/**,./app/services/Firebase/exports/**
        -Dsonar.coverage.exclusions=./database/**,./app/services/Firebase/exports/**
        -Dsonar.host.url=https://sonarcloud.io
        -Dsonar.login=XXX
        -Dsonar.pullrequest.branch=$CODEBUILD_WEBHOOK_HEAD_REF
        -Dsonar.pullrequest.key=$PR_KEY
        -Dsonar.testExecutionReportPaths=./coverage/test-report.xml
        -Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
        -Dsonar.tests=.
        -Dsonar.test.inclusions=**/*.test.js
  • Languages of the repository: javascript
  • Steps to reproduce: Sonar scans run on each PR build, so I get my PR report. However, the files stated in sonar.cpd.exclusions are still getting counted for duplication blocks, and are increasing my duplication percentage.
  • Potential workaround: I do not see a workaround, I just want the specified directories not taken into count when measuring code duplications.

Hey there.

Relative paths cannot be used in sonar.exclusions, sonar.cpd.exclusions, or sonar.coverage.exclusions. Take a look at the example glob patterns here.

You probably want an exclusion closer to:

-Dsonar.coverage.exclusions=database/**/*,app/services/Firebase/exports/**/*

1 Like

This worked. Thanks for the assistance!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.