Wrong project name when using gradle in devops

Hi,
JAVA isn’t much used here, but few projects we have using it, so I set up SonarQube now also for one of these projects using gradle.

  1. I set up the project in sonarqube as usual, with the correct project name
  2. I added relevant build steps (using DevOps extension in version 4 [I know is older, but this devops is customer managed]) for prepare, gradle build and publish and set up connections etc

Result:
The project is correctly analyzed, but the run changed the project name in SonarQube to “s”, which isn’t very helpful. Since there is no way to change the name, except with a new analysis upload, thats bad.

I assume the name “s” is, because the build agent checks the project out into a folder called “s” automatically. I can not influence this folder name.

Steps I tried without success:

  1. I added explicit project name in gradle options:
- task: Gradle@2
    inputs:
      gradleWrapperFile: $(gradleWrapperPath)
      tasks: 'build'
      gradleOptions: '-Dorg.gradle.daemon=false -Xmx2048m -Dsonar.projectName=CUSTOMER_ProjectName'
      options: '--debug'
      javaHomeOption: 'JDKVersion'
      sonarQubeRunAnalysis: true
  1. I checked the debug output, and actually it looks like the project name is correctly sent to sonarQube:
2022-06-08T10:17:27.7491723Z 2022-06-08T12:17:27.719+0200 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] POST 200 https://sonarqube.......com/api/ce/submit?projectKey=xxxxxxxxxxx&projectName=CUSTOMER_ProjectName&characteristic=branch%3Drkg_fix_sonarqube&characteristic=branchType%3DBRANCH | time=1350ms

But the project name is unchanged. This query is for a branch analysis, but neither the master nor the branch name is adapted correctly, also, the only change in this branch is enabling the debug mode.

I am clueless whats going on here. I don’t have any issues with C# or JS/TS projects in the same or other devops projects, only this gradle project.

Any ideas?

Hey there.

You will need to make sure that sonar.projectName is sent along with an analysis of the main branch of the project. In what you shared, it is being sent for a branch analysis.

The main branch controls all branches when it comes to the project name.

Thank you for your reply, but as I mentioned:

This query is for a branch analysis, but neither the master nor the branch name is adapted correctly, also, the only change in this branch is enabling the debug mode.
So, I analysed the main branch with same settings already, only change is enabled debug output

Do you see the correct projectName when you analyze the main branch, like you showed me in the URL below?

Thank you for the hint. You were right. My colleague who was checking this actually told me he did run it on master too, but i just checked it and it wasn’t the case. The change was in master but the CI build doesn’t seem to run on this project on the master regularly due to some strange branching structure.
After running it on master manually now it shows the correct project name - at least in the overview and for the master branch. But the other branches in SonarQube show the wrong name still, no matter if run with correct settings on this branch or not. I guess the name is not updated there, but it’s not a big deal, as long as its correct on the overview page.

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