Duplicated lines are still there even after being excluded

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
    GitHub

  • CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI
    GitHub Actions

  • Scanner command used when applicable (private details masked)

SonarScanner 4.6.2.2472

INFO: Project configuration:
INFO: Excluded sources: ./deploy/ksystem/app/lib/Krystal/src/Interfaces/Netistrar/**/*
INFO: Excluded sources for duplication: ./deploy/ksystem/app/lib/Krystal/src/Interfaces/Netistrar/**/*
  • Languages of the repository
    PHP

  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
    Per the above, the excluded paths for duplicates have been set. However, it is still showing these files as being duplicated after re-running the scan.
    A couple of example files are:

deploy/ksystem/app/lib/Krystal/src/Interfaces/Netistrar/libs/netistrarapi/libs/thirdparty/oauth/oauth.php
deploy/ksystem/app/lib/Krystal/src/Interfaces/Netistrar/libs/thirdparty/oauth/oauth.php

Hi @bencromwell,

The double asterisk pattern will recursively exclude all sub-folders and files. While a single asterisk matches only the files on that specific folder (no recursion). So you can try, for example,

sonar.exclusions = ./deploy/ksystem/app/lib/Krystal/src/Interfaces/Netistrar/**

Best regards,
Fan

Hi Ben,

You might have a look at this explanation and see if it helps

Hello Ben,

The information that you provide is possibly a bit too partial to be sure of what’s happening. Stripping the logs to only what you think is relevant to us starts from a good will, but actually it does not help us because we lose the surrounding context and potentially the information that may explain the problem. We really prefer that you post the full logs.
Let me tell you however what I think i guess.
From

INFO: Project configuration:
INFO: Excluded sources: ./deploy/ksystem/app/lib/Krystal/src/Interfaces/Netistrar/**/*
INFO: Excluded sources for duplication: ./deploy/ksystem/app/lib/Krystal/src/Interfaces/Netistrar/**/*

I understand that you both set:

sonar.exclusions = ./deploy/ksystem/app/lib/Krystal/src/Interfaces/Netistrar/**/*
sonar.cpd.exclusions = ./deploy/ksystem/app/lib/Krystal/src/Interfaces/Netistrar/**/*

You have to decide first if:

  • You want only to exclude the ./deploy/ksystem/app/lib/Krystal/src/Interfaces/Netistrar directory for duplications only (ie these files will be analyzed, there can be issues raised on them, but they will not be counted in the duplication calculation). In that case you should not set sonar.exclusions but set sonar.cpd.exclusions only
  • You want those files to not be analyzed at all (no issues, no duplications, nothing, those files will not even be reported in SonarQube). In that case you’d set sonar.exclusions and not sonar.cdp.exclusions (the latter has no effect since the files are ignored for everything).

Given the paths of those files, I wonder if what you really want is not to exclude those files altogether (they seem to be 3rd party libs that you may not want to analyze, this is not your code), although your post title is quite specific that you want to exclude for duplications only. Up to you to decide.

Anyhow, whatever you want to do I believe that the fact that the analysis settings are not properly taken into account is the ./ prefix you added in the settings. Indeed the scanner will not resolve ./deploy being the same as deploy
So:

# Pick one or the other below depending on exactly what you wand to exclude, but not both,
# sonar.exclusions has a broader effect that includes the effect of sonar.cpd.exclusions

sonar.exclusions=deploy/ksystem/app/lib/Krystal/src/Interfaces/Netistrar/**/*
sonar.cpd.exclusions=deploy/ksystem/app/lib/Krystal/src/Interfaces/Netistrar/**/*

Should fix your problem. Let us know.

Olivier

1 Like

Hi Olivier

Yes, it was the leading ./ that was causing the problem. Having removed it it now seems to be functioning as you’d expect!

1 Like

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