Sonar Maven Plugin cannot find binding or default branch for sonarcloud monorepo project

Hi all,

We have a java multi-module monorepo setup in sonar cloud using github actions to run the maven sonar plugin. However, when the maven sonar plugin makes a call to check if there is a binding or a base branch, it cannot find either.

The project with a matching project Key and organization key already exists in sonarcloud and is bound:

Our module file structure is:

repo root:
- pom.xml (maven plugin and defines apps and libs modules, contains sonar.organization property)
- apps/
-- pom.xml (defines each app module)
-- ...apps
- libs/
-- pom.xml (defines each lib module)
-- core/
--- pom.xml (adds projectKey and related sonar properties)
--- src/
-- core-spring-boot-starter/
--- pom.xmo (adds projectKey and related sonar properties)
--- src/
  • ALM used: GitHub
  • CI system used: Github Actions
  • Scanner command used when applicable:
    •       - name: SonarCloud Analysis - core
              if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
              working-directory: libs/core
              env:
                GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
                SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
                GH_PACKAGE_TOKEN: ${{ secrets.GH_PACKAGE_TOKEN }}
              run: |
                ${{ github.workspace }}/mvnw --settings ${{ github.workspace }}/maven-settings.xml -B --no-transfer-progress sonar:sonar -X \
                -Dsonar.organization=buildops \
                -Dsonar.projectName=buildops_fgaprocessor_core \
                -Dsonar.projectKey=buildops_fgaprocessor_core \
                -Dsonar.pullrequest.key=${{ github.event.number }} \
                -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} \
                -Dsonar.pullrequest.base=main \
                -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \
                -Dsonar.host.url=https://sonarcloud.io \
                -Dsonar.qualitygate.wait=true \
                -Dsonar.qualitygate.timeout=300
      
  • Languages of the repository: Java
  • Error observed:
    • [INFO] Check ALM binding of project 'buildops_fgaprocessor_core'
      [DEBUG] --> GET https://sonarcloud.io/api/alm_integration/is_project_bound?project=buildops_fgaprocessor_core
      [DEBUG] <-- 404 https://sonarcloud.io/api/alm_integration/is_project_bound?project=buildops_fgaprocessor_core (453ms, unknown-length body)
      [INFO] Detected project binding: NONEXISTENT
      [INFO] Check ALM binding of project 'buildops_fgaprocessor_core' (done) | time=455ms
      [INFO] Load project pull requests
      [DEBUG] --> GET https://sonarcloud.io/api/project_pull_requests/list?project=buildops_fgaprocessor_core
      [DEBUG] <-- 404 https://sonarcloud.io/api/project_pull_requests/list?project=buildops_fgaprocessor_core (177ms, unknown-length body)
      [DEBUG] Could not process project pull requests - continuing without it
      [INFO] Load project pull requests (done) | time=181ms
      [INFO] Load branch configuration
      [DEBUG] Found manual configuration of branch/PR analysis. Skipping automatic configuration.
      [DEBUG] Cleanup org.eclipse.jgit.util.FS$FileStoreAttributes$$Lambda$398/0x00007f3e38359c20@7569ea63 during JVM shutdown
      Error:  Could not find a default branch for project with key 'buildops_fgaprocessor_core'. Make sure project exists.
      
    • Its worth nothing that actually navigating the url https://sonarcloud.io/api/project_pull_requests/list?project=buildops_fgaprocessor_core returns a bunch of pull requests, not a 404

Hi,

Many systems will return a 404 error (i.e. what you’ve asked for doesn’t exist) rather than a 403 error, thus admitting that the resource exists but you just don’t have access to it.

You should double-check the PAT you’ve configured SonarQube Cloud with.

 
HTH,
Ann

Thanks Ann,

Turns out this was just a token issue. Throwing a 404 on the project binding check (which also returned a 200 when accessing the url directly) was what put me on the wrong path.

For future readers, the solution in my case was to generate a new scoped sonar token.

Thanks for the help!

1 Like