Hey, thanks for the response!
So I tested the workflow you posted and I got the same results. However, this is what I’m doing that doesn’t look right:
- Locally in a gradle managed repository, I create a feature branch:
$ git checkout -b feature
Switched to a new branch 'feature'
- I added this method in a file, in a project
private void method1() {
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
System.out.println("This is method1");
}
- I commit it
git add .
git commit -m "First commit"
This is the commit tree at this point:
3118e935dcae8605c81d3761f7eb2b9652d00e13 (HEAD -> feature) First commit
82459e42eb58f4e275ad14519b11131174e2d092 (origin/master, origin/HEAD, master) Merge pull request #64986 ...
bebabd3320f95aca7635b37647dfeea0dc0c2f6b Merge pull request #65206 ...
583c2e05ada1f16b3179c2d8ff77f4016cddb733 Merge pull request #65205 ...
8d05c25cac1faaa1e25a4fef243ba8a94c869380 Merge pull request #65173 ...
da5f065f1ff16c0e97dbba2cd50aee8932fa81f3 Merge pull request #65202 ...
0dafcecbbb7999a3cd2e201ea4212abbd70769a3 Merge pull request #65188 ...
7493accb1cd77c88f4109460e11aa6a0212cb486 Merge pull request #65155 ...
ed3e4b302327681fbe95584b2ebad20c0d034ed4 Merge pull request #65187 ...
686ca05cbd8141337855b93d249fb7b8ba5f4fca Merge pull request #65149 ...
b6e266d19574c5190e15d81f3cc0e1f2b6d2bf13 Merge pull request #65185 ...
743cb7a0d06537bc0af1b477feb3ffdcfc52fa7e Merge pull request #65130 ...
4f52d5e3f2f05a481fee33d256a3e88eac29861d Merge pull request #65186 ...
9f8fe6a0e1b31c5c55815ed2b284a4282095d048 Merge pull request #65162 ...
3b9bfc19d0eadd8cd07af9dbedbe50a744badc5a Merge pull request #64980 ...
- I run the sonarqube gradle task
gradlew :project:sonarqube --debug
...
2021-06-07T13:37:17.263+0300 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Merge base sha1: 82459e42eb58f4e275ad14519b11131174e2d092
Looks right.
- Now checking results in Sonarqube:
Perfect so far.
- Going back to the git repo, I switch to master, pull from origin, switch to feature and merge with master
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
$ git pull
remote: Enumerating objects: 328, done.
remote: Counting objects: 100% (328/328), done.
remote: Compressing objects: 100% (210/210), done.
remote: Total 328 (delta 89), reused 114 (delta 42)
Receiving objects: 100% (328/328), 93.04 KiB | 727.00 KiB/s, done.
Resolving deltas: 100% (89/89), completed with 22 local objects.
...
$ git checkout feature
Switched to branch 'feature'
$ git merge master
...
At this point, this is how the commit tree looks like:
$ git --no-pager log --decorate=short --pretty=oneline -n15
05e89f9599fe352054716237e849f4467c8420df (HEAD -> feature) Merge branch 'master' into feature
d14190f6a89222fcd637e11cc4eb6745020344f5 (origin/master, origin/HEAD, master) Merge pull request #65124 ...
3118e935dcae8605c81d3761f7eb2b9652d00e13 First commit
e28fa35453595c8654f6872b7a195bc7e80b4c2e Merge pull request #65170 ...
5090eba07af834e10a1bdd550a4cea72d0d73108 Merge pull request #65182 ...
82459e42eb58f4e275ad14519b11131174e2d092 Merge pull request #64986 ...
bebabd3320f95aca7635b37647dfeea0dc0c2f6b Merge pull request #65206 ...
583c2e05ada1f16b3179c2d8ff77f4016cddb733 Merge pull request #65205 ...
8d05c25cac1faaa1e25a4fef243ba8a94c869380 Merge pull request #65173 ...
da5f065f1ff16c0e97dbba2cd50aee8932fa81f3 Merge pull request #65202 ...
0dafcecbbb7999a3cd2e201ea4212abbd70769a3 Merge pull request #65188 ...
7493accb1cd77c88f4109460e11aa6a0212cb486 Merge pull request #65155 ...
ed3e4b302327681fbe95584b2ebad20c0d034ed4 Merge pull request #65187 ...
686ca05cbd8141337855b93d249fb7b8ba5f4fca Merge pull request #65149 ...
b6e266d19574c5190e15d81f3cc0e1f2b6d2bf13 Merge pull request #65185 ...
- Now I add some more code and commit it.
This is what I add:
private void method2() {
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
System.out.println("This is method2");
}
And I commit it:
$ git add .
$ git commit -m "Second commit"
[feature d7c2caef89c] Second commit
1 file changed, 27 insertions(+)
This is how the commit tree looks like:
$ git --no-pager log --decorate=short --pretty=oneline -n15
d7c2caef89c4171a5f58ea284ec5b80998f27336 (HEAD -> feature) Second commit
05e89f9599fe352054716237e849f4467c8420df Merge branch 'master' into feature
d14190f6a89222fcd637e11cc4eb6745020344f5 (origin/master, origin/HEAD, master) Merge pull request #65124 in SITE/weightsite from IPD-179180 to master
3118e935dcae8605c81d3761f7eb2b9652d00e13 First commit
e28fa35453595c8654f6872b7a195bc7e80b4c2e Merge pull request #65170 ...
5090eba07af834e10a1bdd550a4cea72d0d73108 Merge pull request #65182 ...
82459e42eb58f4e275ad14519b11131174e2d092 Merge pull request #64986 ...
bebabd3320f95aca7635b37647dfeea0dc0c2f6b Merge pull request #65206 ...
583c2e05ada1f16b3179c2d8ff77f4016cddb733 Merge pull request #65205 ...
8d05c25cac1faaa1e25a4fef243ba8a94c869380 Merge pull request #65173 ...
da5f065f1ff16c0e97dbba2cd50aee8932fa81f3 Merge pull request #65202 ...
0dafcecbbb7999a3cd2e201ea4212abbd70769a3 Merge pull request #65188 ...
7493accb1cd77c88f4109460e11aa6a0212cb486 Merge pull request #65155 ...
ed3e4b302327681fbe95584b2ebad20c0d034ed4 Merge pull request #65187 ...
686ca05cbd8141337855b93d249fb7b8ba5f4fca Merge pull request #65149 ...
- Running the sonarqube task again:
gradlew :project:sonarqube --debug
...
2021-06-07T13:43:27.273+0300 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Merge base sha1: d14190f6a89222fcd637e11cc4eb6745020344f5
Looks right.
- Now checking results in Sonarqube:
Well, looks like it only detected the changes from my 2nd commit as New code. You can actually see a chunk of the 1st method I created at the top of the screenshot.
Also these are the project settings for New Code:
We have a gradle plugin which figures out the branch automatically and sets it like this:
project.sonarqube {
properties {
...
property "sonar.branch.name", "${project.gitRevisions.branch}"
Anyway, it looks like it figured it out correctly, judging by what I see in Sonarqube and the debug logs:
...
ANALYSIS SUCCESSFUL, you can browse https://sonarqube.site-ops.fitbit.com/dashboard?id=project&branch=feature
...
This is the full list of sonarqube settings in the gradle plugin:
project.sonarqube {
properties {
property "sonar.projectKey", "${project.ids.sonarKey}"
property "sonar.projectName", "${projectName}"
property "sonar.branch.name", "${project.gitRevisions.branch}"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.test.inclusions", "**/*Test*/**"
property "sonar.language", "java"
property "sonar.coverage.jacoco.xmlReportPaths", [project.fileTree(dir: "${project.buildDir}/reports/jacoco", include: '**/*.xml')]
property "sonar.java.binaries", "$project.buildDir/classes"
property "sonar.host.url", "${project.property("systemProp.sonar.host.url")}"
property "sonar.dependencyCheck.reportPath", dependencyReportPath
property "sonar.dependencyCheck.htmlReportPath", "${project.buildDir.path}/reports/dependency-check-report.html"
// extend exclusions set by projects
properties["sonar.exclusions"] = (properties["sonar.exclusions"] ?: []) + ["**/*Test*/**","**/generatedsrc/**","**/generated-src/**", "**/gen-src/**", "**/generated/main/**", "**/generated/test/**"]
}
}
Best regards,
Stefan