# New Code Definition is working wrong

**URL:** <https://community.sonarsource.com/t/new-code-definition-is-working-wrong/57462>\
**Category:** SonarQube Server / Community Build\
**Tags:** new\_code, sonarqube\
**Created:** [February 2, 2022, 7:59am UTC](https://community.sonarsource.com/t/new-code-definition-is-working-wrong/57462 "2022-02-02T07:59:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hakanaltindis](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/hakanaltindis/32/16214_2.png) [@hakanaltindis](https://community.sonarsource.com/u/hakanaltindis)\
**Post date:** [February 2, 2022, 7:59am UTC](https://community.sonarsource.com/t/new-code-definition-is-working-wrong/57462/1 "2022-02-02T07:59:33Z")

</div>

Hi,

We were using Sonarqube Enterprise Edition and it’s version is 9.2 and we upgraded it to 9.3 yesterday. So we always use latest version for Enterprise Edition.

I think Sonarqube New Code definition is working wrong. I will try to tell you with our example.

You can see what our project’s New Code definition is.

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/9/7/97309076bc9fbd55a1f96be379567f2508f3b8ed.png)

I think Sonarqube should calculate difference code from the previous version. But it did not do that.

P.S. We scan our repository’s develop branch on Sonarqube every night as scheduled. So the previous version is yesterday’s scan.

We work with feature branches in our repository. Basically, we create new feature branch from develop, then we develop our features in the feature branch. Sometimes it takes one or more weeks. We did a lot of commits in this duration. After we finish developing, we merge the feature branch to develop. And that night, Sonarqube scan develop branch again. I think the merged feature branch’s codes is all new code. But Sonarqube only considers commits made that day(last day). Previous commits’ codes are not shown in New Code reports.

I hope I was able to explain my problem.

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:** [February 2, 2022, 9:45am UTC](https://community.sonarsource.com/t/new-code-definition-is-working-wrong/57462/2 "2022-02-02T09:45:17Z")

</div>

Hey there.

It sounds like you might be passing a brand new version to `sonar.projectVersion` on each analysis, which would reset the New Code Period on your `develop` branch with every scan. Ideally, when using the **Previous Version** New Code Period the version should only be updated when there has actually been a version cut (a milestone, a new release, etc.)

You can check this in the **Activity** tab of your project.

---

<div class="post-metadata">

**Author:** ![hakanaltindis](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/hakanaltindis/32/16214_2.png) [@hakanaltindis](https://community.sonarsource.com/u/hakanaltindis)\
**Post date:** [February 2, 2022, 10:21am UTC](https://community.sonarsource.com/t/new-code-definition-is-working-wrong/57462/3 "2022-02-02T10:21:34Z")

</div>

Hi,

Yes, We set version with pipeline build id every scan as you can see below image. I think you said set a static variable to it?

I will try to set a static value in this night scan.

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/a/4/a4b11eb15a05f1d501694913c59d282e9668ad69.png)

---

<div class="post-metadata">

**Author:** ![hakanaltindis](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/hakanaltindis/32/16214_2.png) [@hakanaltindis](https://community.sonarsource.com/u/hakanaltindis)\
**Post date:** [February 7, 2022, 6:58am UTC](https://community.sonarsource.com/t/new-code-definition-is-working-wrong/57462/4 "2022-02-07T06:58:36Z")

</div>

Hi @Colin ,  
I tried your suggestion. And I fixed the Sonarqube Project’s version nubmer. After that, the New Code definition shows as “Started 5 days ago”. As you can see the below image. It means it takes 5 days period.

![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/3/3/3385fc5b2348879e300d9e2dd49ced220fa9dc0f.png)

But I tried to tell before. I want to see all merged branches, commits to develop in new code report for every day. Is there any other suggestions?

Thanks.

---

<div class="post-metadata">

**Author:** ![Jesus\_Beltran](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/jesus_beltran/32/36686_2.png) [@Jesus\_Beltran](https://community.sonarsource.com/u/Jesus_Beltran)\
**Post date:** [August 31, 2022, 5:32am UTC](https://community.sonarsource.com/t/new-code-definition-is-working-wrong/57462/7 "2022-08-31T05:32:03Z")

</div>

Hi! I have the same problem. Did you solve it?
