# Sonar.cpd.exclusions not working as intended

**URL:** <https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523>\
**Category:** SonarQube Cloud\
**Tags:** duplications, coverage\
**Created:** [April 2, 2024, 5:01pm UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523 "2024-04-02T17:01:29Z")\
**Posts on this page:** 12\
**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:** [April 2, 2024, 5:01pm UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523/1 "2024-04-02T17:01:29Z")

</div>

Greetings,

This is my sonar property file

```auto
sonar.sources=bin/,models/,mongo/,utils/,Dockerfile,\
Jenkinsfile,Jenkinsfile-dev,swagger.js,server.js,ecosystem-dev.config.js
sonar.tests=test/
sonar.cpd.exclusions=package.json, sonarcloud/**/*
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-

```

`sonarcloud` is a directory we have which houses some files that was needed for the sonarcloud setup. The file and directory given in the `cpd.exclusions` are not being recignised in the analysis log and hence, they can be seen in the portal under the duplications tab. I am attaching both the analysis log and the portal screenshot  
 ![Screenshot 2024-04-02 at 11.48.28 AM](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/6/5/659a90aba888bdf2228f9afd1e13d5bcf91a4a8e.png)

 ![Screenshot 2024-04-02 at 11.59.53 AM](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/d/9/d9bf958f3068f8fd4adf0a208154780c223b3cb2.png)

In addition, test directory is also being considered for duplications. Is the properties mentioned wrong? Would love to get some insight.

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [April 4, 2024, 8:29am UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523/2 "2024-04-04T08:29:44Z")

</div>

Hey there.

You’re doing everything right – but when you exclude a file from duplication, that duplication gets set to 0%, not null (like for coverage). I am not really sure why, but I’m going to throw this over to somebody who might. 😃

---

<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:** [April 4, 2024, 4:50pm UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523/7 "2024-04-04T16:50:08Z")

</div>

Hey @Colin ,

Thanks a lot for the reply. I request to get in touch with the other person as soon as possible as this issue needs to be addressed urgently on our end. Thanks

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [April 4, 2024, 5:26pm UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523/8 "2024-04-04T17:26:23Z")

</div>

Hey there.

I can’t understand what’s making this urgent — the values are being set to 0. Can you explain?

---

<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:** [April 4, 2024, 5:39pm UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523/9 "2024-04-04T17:39:37Z")

</div>

We would like the test folder , its contents and the files given in the exclusions to not show up in the duplications tab. I was facing a similar issue for coverage but that’s worked out. Here is my coverage tab,

 ![Screenshot 2024-04-04 at 12.37.57 PM](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/9/6/96deb8167e2906d7a01b301e447f1bd9fe3ffae0.png). Since the duplications have not been configured, we cannot integrate sonarcloud into our workflow, which we have been trying to do for 2 months now.

---

<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:** [April 8, 2024, 3:08pm UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523/10 "2024-04-08T15:08:44Z")

</div>

Hey @Colin ,

Were you able to get in touch with the relevant personnel? Thanks

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [April 8, 2024, 3:18pm UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523/11 "2024-04-08T15:18:17Z")

</div>

Hey @Venkatesh_Ragavan

This is how our products have worked for a long time, and we consider it more of a quirk than a bug. Somebody will look at it as time permits.

> [@Venkatesh\_Ragavan](#):
>
> We would like the test folder , its contents and the files given in the exclusions to not show up in the duplications tab.

Understood. And, that should not block you from integrate SonarCloud into your workflow.

> [@Venkatesh\_Ragavan](#):
>
> which we have been trying to do for 2 months now.

It’s a shame we only heard from you about this last week! 😃

---

<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:** [April 8, 2024, 3:35pm UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523/12 "2024-04-08T15:35:39Z")

</div>

Hey Colin,

Thanks for the response. So to clarify, despite the test directory and its contents being excluded for duplications, they’ll be shown in that screen. Is my understanding correct? Does this apply to all duplication patterns?

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [April 9, 2024, 2:08pm UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523/13 "2024-04-09T14:08:46Z")

</div>

Yes. Even if you exclude all files (`**/*`), Duplication will be 0%, not null.

---

<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:** [April 9, 2024, 2:37pm UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523/14 "2024-04-09T14:37:48Z")

</div>

Hey Colin,

Thanks for the response. Now i understand. However, going by my observation, coverage can be null correct?

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [April 10, 2024, 1:11pm UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523/15 "2024-04-10T13:11:16Z")

</div>

Correct. This is the weird quirk I think we (Sonar) should look at and figure out if there’s any good reason for this.

---

<div class="post-metadata">

**Author:** ![AlexanderOrlov](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexanderorlov/32/40558_2.png) [@AlexanderOrlov](https://community.sonarsource.com/u/AlexanderOrlov)\
**Post date:** [May 27, 2024, 8:30am UTC](https://community.sonarsource.com/t/sonar-cpd-exclusions-not-working-as-intended/112523/30 "2024-05-27T08:30:41Z")

</div>

Hello @Venkatesh_Ragavan,

We have created a ticket to improve this behavior in the future.
