# Sonarcloud cpd exclusions being ignored in the log

**URL:** <https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221>\
**Category:** SonarQube Cloud\
**Tags:** duplications, sonarqube-cloud, coverage\
**Created:** [March 28, 2024, 4:35am UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221 "2024-03-28T04:35:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Venkatesh\_Ragavan](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/venkatesh_ragavan/32/53796_2.png) [@Venkatesh\_Ragavan](https://community.sonarsource.com/u/Venkatesh_Ragavan)\
**Post date:** [March 28, 2024, 4:35am UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/1 "2024-03-28T04:35:52Z")

</div>

Greetings,

I am sonarCloud for my project. I am trying to setup the code coverage for the project. I use a local script called ‘test-coverage’ in conjunction with npm to generate the coverage reports. They are generated in the coverage directory. Sonarcloud successfully detects the reports . However, I want it to exclude the folder `test` from duplication by giving it in the `sonar.cpd.exclusions` parameter. However, the analysis ignores that parameter. I would like to get some insights about what might be going on. Here is the `sonar-project.properties` file

```auto
sonar.organization=xxxx
sonar.projectKey=xxx
sonar.host.url=https://sonarcloud.io
sonar.sourceEncoding=UTF-8
sonar.sources=./
sonar.exclusions= **/node_modules/** , **/helmchart/**
sonar.coverage.exclusions= **/test/** /*.*
sonar.cpd.exclusions= **/test/** /*.* 
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.c.file.suffixes=- 
sonar.cpp.file.suffixes=- 

```

Here is

 ![Screenshot 2024-03-28 at 3.12.24 PM](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/1/2/12811efcb476e5f9a856e1de4474f245d87bb79e.png)  
the analysis log

Any insight would be appreciated.

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 29, 2024, 1:15pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/2 "2024-03-29T13:15:51Z")

</div>

Hi,

Where are your test files located? Are they all under a single directory named `test`, or are there multiple `test` directories? Because there’s an easier way than how you’re currently approaching it:

```auto
// set source file locations to current directory, recursive
sonar.sources=.
// set test file locations to the test directory, recursive
sonar.tests=test
// at this point everything under test will be indexed 
// as both a source file and a test file, thus => analysis error
// so we have to keep the test files from being indexed as source
sonar.exclusions=test/**/*

```

Test files are automatically excluded from coverage and duplication calculations, so at this point, you’re done.

&nbsp;  
HTH,  
Ann

---

<div class="post-metadata">

**Author:** ![Venkatesh\_Ragavan](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/venkatesh_ragavan/32/53796_2.png) [@Venkatesh\_Ragavan](https://community.sonarsource.com/u/Venkatesh_Ragavan)\
**Post date:** [March 29, 2024, 3:31pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/3 "2024-03-29T15:31:06Z")

</div>

Hey Ann,

Thanks for the reply. I will try it. I also want another query resolved. I am trying to exclude a whole bunch of directories and files from coverage and duplications.

```auto
**sonar.coverage.exclusions=** /test/ **,** /bin/ **,** /config/ **,** /jest-stare/ **,** /keys/ **,** /logs/**, \
**/.*,** /*.js, **/*.json,** /*.yml, **/*.yaml,** /README.md, **/Jenkins*,** /Docker*, **/.*/**

sonar.cpd.exclusions= **/test/** , **/bin/** , **/config/** , **/jest-stare/** , **/keys/** , **/logs/** , \
**/.*,** /*.js, **/*.json,** /*.yml, **/*.yaml,** /README.md, **/Jenkins*,** /Docker*, **/.*/**

```

Ignoring the test directory, the analysis log is still not considering the other directories. I have tried seperating each directory or file with a comma, a comma + space and a comma + 2 spaces( as in this case ). The analysis log ignores the other directories. What’s going wrong here? And surprisingly, it doesnt show the ` **/test/** ` but ` **/test/** /*.*` which was a previous commit.

 ![Screenshot 2024-03-29 at 10.30.02 AM](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/c/3/c3ba3fdf259e5815f5c902a669a94b6aac8e7a74.png)

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 29, 2024, 3:45pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/4 "2024-03-29T15:45:42Z")

</div>

Hi,

We try to keep it to one topic per thread. Otherwise it can get messy, fast. Since this seems related, I’ll give a quick answer, but reserve the right to ask you to create a new thread.

> [@Venkatesh\_Ragavan](#):
>
> ```auto
> **sonar.coverage.exclusions=** /test/ **,** /bin/ **,** /config/ **,** /jest-stare/ **,** /keys/ **,** /logs/**, \
> **/.*,** /*.js, **/*.json,** /*.yml, **/*.yaml,** /README.md, **/Jenkins*,** /Docker*, **/.*/**
> 
> sonar.cpd.exclusions= **/test/** , **/bin/** , **/config/** , **/jest-stare/** , **/keys/** , **/logs/** , \
> **/.*,** /*.js, **/*.json,** /*.yml, **/*.yaml,** /README.md, **/Jenkins*,** /Docker*, **/.*/**
> 
> ```

As I said earlier, files recognized by analysis as test files are naturally excluded from coverage and duplications calculations, so no need to include them in this list.

But beyond that, I’m starting to really question your definition of `sonar.sources` as `.`.

Where, exactly are your source files located? Because I’m starting to think it would be a whole lot easier to set a good, tight definition there than to get all these exclusions set up.

That said, ` **` excludes 0-n _directories_. To exclude the files in them, you’ll need to finish the patterns with `/*`. E.G. `** /config/**/*`.

&nbsp;  
HTH,  
Ann

---

<div class="post-metadata">

**Author:** ![Venkatesh\_Ragavan](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/venkatesh_ragavan/32/53796_2.png) [@Venkatesh\_Ragavan](https://community.sonarsource.com/u/Venkatesh_Ragavan)\
**Post date:** [March 29, 2024, 3:52pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/5 "2024-03-29T15:52:35Z")

</div>

Hey Ann,

Thanks for the reply. I wanted the topmost level of the repo to be the source. Since that’s the origin of the path, I figured giving `.` would be appropriate.

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 29, 2024, 3:53pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/6 "2024-03-29T15:53:17Z")

</div>

Hi,

> [@Venkatesh\_Ragavan](#):
>
> I wanted the topmost level of the repo to be the source

Okay, but why? What’s it getting you but a lot of extra work?

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Venkatesh\_Ragavan](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/venkatesh_ragavan/32/53796_2.png) [@Venkatesh\_Ragavan](https://community.sonarsource.com/u/Venkatesh_Ragavan)\
**Post date:** [March 29, 2024, 3:54pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/7 "2024-03-29T15:54:39Z")

</div>

Since all the directories and code files are in there and I wanted them all to be covered for the analysis.

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 29, 2024, 3:56pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/8 "2024-03-29T15:56:59Z")

</div>

Hi,

> [@Venkatesh\_Ragavan](#):
>
> I wanted them all to be covered for the analysis.

Except… you don’t? Otherwise you wouldn’t need all these exceptions.

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Venkatesh\_Ragavan](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/venkatesh_ragavan/32/53796_2.png) [@Venkatesh\_Ragavan](https://community.sonarsource.com/u/Venkatesh_Ragavan)\
**Post date:** [March 29, 2024, 4:00pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/9 "2024-03-29T16:00:51Z")

</div>

Hey Ann,

I get your point. However, there are about 15 directories/files in total. I want the analysis to cover about 6-8 of them. So I would be anyway required to mentioned them explicitly. Hence, I though I could mention the directories I do not want as exclusions. But what do you suggest?

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 29, 2024, 4:06pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/10 "2024-03-29T16:06:48Z")

</div>

Hi,

I suggest:

```auto
sonar.sources=dir1,dir2,dir3,dir4,dir5,dir6,dir7,dir8
sonar.tests=test

```

So much simpler, IMO. And less typing too 😂

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Venkatesh\_Ragavan](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/venkatesh_ragavan/32/53796_2.png) [@Venkatesh\_Ragavan](https://community.sonarsource.com/u/Venkatesh_Ragavan)\
**Post date:** [March 29, 2024, 4:08pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/11 "2024-03-29T16:08:11Z")

</div>

Hey Ann,

While giving the directory/file names for `sonar.sources`, do we need to use the wildcards to ensure its contents get covered too?

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 29, 2024, 4:09pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/12 "2024-03-29T16:09:24Z")

</div>

Hi,

The rules are slightly different for `sonar.sources`. It takes a comma-delimited list of directories, which will be scanned recursively. So it’s really just like I listed it: `dir1,dir2` &etc.

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Venkatesh\_Ragavan](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/venkatesh_ragavan/32/53796_2.png) [@Venkatesh\_Ragavan](https://community.sonarsource.com/u/Venkatesh_Ragavan)\
**Post date:** [March 29, 2024, 4:11pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/13 "2024-03-29T16:11:34Z")

</div>

Hey Ann,

Sounds good. Can code files be listed in the comma seperated way too? Let’s say I have 2 dirs, dir1, dir2 and a code file named, trial.js. Would `sonar.sources=dir1,dir2,trial.js` work?

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 29, 2024, 4:14pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/14 "2024-03-29T16:14:23Z")

</div>

Hi,

I had to look [that one up](https://docs.sonarsource.com/sonarcloud/advanced-setup/analysis-parameters/#analysis-scope): yes.

&nbsp;  
HTH,  
Ann

---

<div class="post-metadata">

**Author:** ![Venkatesh\_Ragavan](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/venkatesh_ragavan/32/53796_2.png) [@Venkatesh\_Ragavan](https://community.sonarsource.com/u/Venkatesh_Ragavan)\
**Post date:** [March 29, 2024, 4:24pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/15 "2024-03-29T16:24:22Z")

</div>

Hey Ann,

Thanks a lot for the replies. I was curious about one thing. If you refer to my 2nd post where I asked about multiple directory exclusions, I mentioned about the analysis log showing its excluding the test directory but the pattern shown was of the previous commit. Do you know why that’s happening?

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 29, 2024, 4:26pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/16 "2024-03-29T16:26:52Z")

</div>

Hi,

> [@Venkatesh\_Ragavan](#):
>
> analysis log showing its excluding the test directory but the pattern shown was of the previous commit.

No clue. Analysis acts on the code that was checked out into the workspace, so this is likely a question of what’s going on in your workflow/CI.

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Venkatesh\_Ragavan](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/venkatesh_ragavan/32/53796_2.png) [@Venkatesh\_Ragavan](https://community.sonarsource.com/u/Venkatesh_Ragavan)\
**Post date:** [March 29, 2024, 4:31pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/17 "2024-03-29T16:31:39Z")

</div>

Hey Ann,

One more query. Let’s say I want the test files to be included in analysis but be removed from coverage and duplications alone. Would the code suggested below work?

```auto
// set source file locations to current directory, recursive
sonar.sources=.
// set test file locations to the test directory, recursive
sonar.tests=test
// at this point everything under test will be indexed 
// as both a source file and a test file, thus => analysis error
// so we have to keep the test files from being indexed as source
sonar.exclusions=test/**/*

```

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 29, 2024, 4:39pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/18 "2024-03-29T16:39:38Z")

</div>

Hi,

I’m very tempted to tell you to create a new thread for this “one more” question. 🙂

No. It would not work. Read the comments.

You would have to do the explicit coverage and duplications exclusions.

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Venkatesh\_Ragavan](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/venkatesh_ragavan/32/53796_2.png) [@Venkatesh\_Ragavan](https://community.sonarsource.com/u/Venkatesh_Ragavan)\
**Post date:** [March 29, 2024, 4:40pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/19 "2024-03-29T16:40:21Z")

</div>

Hey Ann,

Thanks for the replies.

---

<div class="post-metadata">

**Author:** ![Venkatesh\_Ragavan](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/venkatesh_ragavan/32/53796_2.png) [@Venkatesh\_Ragavan](https://community.sonarsource.com/u/Venkatesh_Ragavan)\
**Post date:** [March 29, 2024, 4:45pm UTC](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221/20 "2024-03-29T16:45:57Z")

</div>

Hey Ann,

While giving a list of file exclusions for cpd or any such list of exclusions, can we use `\`to give the files names in a new line in the `sonar-project.properties` file. I was unable to find info on this.

[Next page](https://community.sonarsource.com/t/sonarcloud-cpd-exclusions-being-ignored-in-the-log/112221.md?page=2)
