SonarQube gradle plugin v6 not creating project in Sonar Cloud

We are using org.sonarqube gradle plugin to analyze our Java code and upload results to https://sonarcloud.io/ . Up to version 5.1 the plugin created a new project in sonarcloud when I was setting up a new java application.

After the upgrade to version 6.0.0.5145, the task runs fine, but no project is created in Sonar Cloud, so no results are uploaded.

After downgrading the plugin to 5.1.0.4882, the project was created, so I could continue using 6.0.0.5145 .

Is that intended? What must I change in my pipelines to get projects created automatically?
Or is it a bug?

Hey there.

Can you share the logs of the gradle task?

./gradlew --warning-mode all -PsdaNexusUser=**** -PsdaNexusPassword=**** sonarqube -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=sda-se -Dsonar.coverage.jacoco.xmlReportPaths=**/path/to/jacocoTestReport.xml -Dsonar.qualitygate.wait=true -Dsonar.scm.provider=git -Dsonar.projectKey=epa-dlt-watchdog -Dsonar.token=**** -Dsonar.pullrequest.key=6 -Dsonar.pullrequest.base=main -Dsonar.pullrequest.branch=initial-quarkus-setup -Dsonar.pullrequest.provider=github -Dsonar.pullrequest.github.repository=***** -Dsonar.pullrequest.github.endpoint=https://api.github.com/ -Dsonar.userHome=/path/to/build/.sonar -Dsonar.exclusions= -Dsonar.coverage.exclusions= --info --stacktrace

… than a lot of gradle default output…

Starting SonarScanner Engine...
Java 17.0.11 Eclipse Adoptium (64-bit)
Load global settings
Load global settings (done) | time=496ms
Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
Loading required plugins
Load plugins index
Load plugins index (done) | time=71ms
Load/download plugins
Load/download plugins (done) | time=1505ms
Found an active CI vendor: 'Jenkins'
Load project settings for component key: 'epa-dlt-watchdog'
Process project properties
Project key: epa-dlt-watchdog
Base dir: /path/to/workspace
Working dir: /path/to/workspace/build/sonar
Load project branches
Load project branches (done) | time=53ms
Check ALM binding of project 'epa-dlt-watchdog'
Detected project binding: NONEXISTENT
Check ALM binding of project 'epa-dlt-watchdog' (done) | time=52ms
Load project pull requests
Load project pull requests (done) | time=62ms
Load branch configuration
Could not find a default branch for project with key 'epa-dlt-watchdog'. Make sure project exists.

Oh, it even says: Could not find a default branch for project with key 'epa-dlt-watchdog'. Make sure project exists.

Using 5.1 it just creates the project.

Seems related to Could not find a default branch for project with key

Hey there.

Typically we see this error when sonar.branch.name or sonar.pullrequest.* is set (explicitly or via auto-configuration) and the project does not exist yet.

We have an internal ticket to solve this (provision project when branch configuration is provided), a feature already present in the SonarQube Server.

Are you sure this exact command is working with v5 of the Gradle plugin when the project doesn’t exist? Or could v5 have been working well absent the sonar.pullrequest.* parameters (it would be expected to fail with them)

To test this out, I used v6 of the Scanner for Gradle and had no problem auto-provisioning a project locally.

Hi Colin,

finally I found the root cause: Our pipeline already has a handling for the problem of not creating projects when sonar.branch.name or sonar.pullrequest.* or pullRequest parameters are set. If the build fails, it will run the command without any of these parameters to create the project.

The difference v5 vs v6 is (drum rolls): In v6 the build doesn’t fail on Could not find a default branch for project with key 'epa-dlt-watchdog'. Make sure project exists. while v5 does (see below)

Is that a bug to be fixed?

Using v6
./gradlew --warning-mode all sonarqube -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=sda-se -Dsonar.qualitygate.wait=true -Dsonar.scm.provider=git -Dsonar.projectKey=epa-dlt-watchdog -Dsonar.token=**** -Dsonar.pullrequest.key=6 -Dsonar.pullrequest.base=main -Dsonar.pullrequest.branch=initial-quarkus-setup -Dsonar.pullrequest.provider=github -Dsonar.pullrequest.github.repository=**** -Dsonar.pullrequest.github.endpoint=https://api.github.com/ -Dsonar.exclusions= -Dsonar.coverage.exclusions=

Outcome:

  • Could not find a default branch for project with key 'epa-dlt-watchdog'. Make sure project exists.
  • Project has not been created
  • Build succeeds

./gradlew --warning-mode all sonarqube -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=sda-se -Dsonar.qualitygate.wait=true -Dsonar.scm.provider=git -Dsonar.projectKey=epa-dlt-watchdog -Dsonar.token=**** -Dsonar.pullrequest.github.endpoint=https://api.github.com/ -Dsonar.exclusions= -Dsonar.coverage.exclusions=

Outcome:

  • Project has been created
  • Build succeeds

./gradlew --warning-mode all sonarqube -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=sda-se -Dsonar.qualitygate.wait=true -Dsonar.scm.provider=git -Dsonar.projectKey=e pa-dlt-watchdog -Dsonar.token=***** -Dsonar.branch.name=main -Dsonar.exclusions= -Dsonar.coverage.exclusions=

Outcome:

  • Could not find a default branch for project with key 'epa-dlt-watchdog'. Make sure project exists.
  • Project has not been created
  • Build succeeds

Using v5.1

./gradlew --warning-mode all sonarqube -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=sda-se -Dsonar.qualitygate.wait=true -Dsonar.scm.provider=git -Dsonar.projectKey=epa-dlt-watchdog -Dsonar.token=***** -Dsonar.pullrequest.key=6 -Dsonar.pullrequest.base=main -Dsonar.pullrequest.branch=initial-quarkus-setup -Dsonar.pullrequest.provider=github -Dsonar.pullrequest.github.repository=SDA-SE/epa-dlt-watchdog -Dsonar.pullrequest.github.endpoint=https://api.github.com/ -Dsonar.exclusions= -Dsonar.coverage.exclusions=

Outcome:

  • Could not find a default branch for project with key 'epa-dlt-watchdog'. Make sure project exists.
  • Project has not been created
  • Build fails

./gradlew --warning-mode all sonarqube -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=sda-se -Dsonar.qualitygate.wait=true -Dsonar.scm.provider=git -Dsonar.projectKey=e pa-dlt-watchdog -Dsonar.token=***** -Dsonar.branch.name=main -Dsonar.exclusions= -Dsonar.coverage.exclusions=

Outcome:

  • Could not find a default branch for project with key 'epa-dlt-watchdog'. Make sure project exists.
  • Project has not been created
  • Build fails

Seems we are lucky, Release 6.0.1 · SonarSource/sonar-scanner-gradle · GitHub solved the issue

1 Like