Start FreeLog in
SonarQube Cloud | Advanced setup | Monorepo support

Monorepo support

On this page

SonarQube Cloud supports repositories that use the monorepo strategy.

What is a monorepo?

Traditionally, software projects have been organized so that each project is stored within a single, distinct repository of its own.

As software projects have become more complex and interconnected, some organizations have moved to having all their projects in a single large repository. This is called the monorepo strategy.

In a typical monorepo, each project occupies its own directory within the repository and each is independently buildable and deployable, though the exact setup depends on how the procedures that build each project are defined. In general, there are many ways that multiple projects can be arranged within a single repository.

Fortunately, SonarQube Cloud's support for the monorepo strategy does not depend on the specifics of the monorepo setup. SonarQube Cloud relies on the fact that each build procedure can be configured to perform the analysis for its particular project in the repository and send the result to the corresponding SonarQube Cloud project.

Setting up the analysis of a monorepo

In a standard setup, each SonarQube Cloud project corresponds to a single repository. In a monorepo setup, multiple SonarQube Cloud projects, each corresponding to a separate monorepo project, are all bound to the same repository. This way:

  • The analysis setup of each project in the monorepo is easier. 
  • When you do an analysis, information from SonarQube Cloud that appears in the pull request view is clearly distinguished by project name. 
  • The monorepo associated with a project is shown in the SonarQube Cloud UI.

Currently, monorepo support is available for GitHub, Bitbucket Cloud, Azure DevOps and GitLab repositories. Note that the analysis of a monorepo configuration is only supported for CI service setups, not automatic analysis setups.

Set up overview

To set up the analysis of a monorepo:

  1. Import the monorepo to SonarQube Cloud in order to create the monorepo projects in SonarQube Cloud. 
  2. Add the SonarQube Cloud analysis to your monorepo's CI pipeline.

Note that each SonarQube Cloud project must have a key unique across SonarQube Cloud (see Analysis Parameters). This is the key that you will use when you configure your CI service. It binds the project in the monorepo to its corresponding SonarQube Cloud project. We recommend using a pattern that includes your organization name, the SonarQube Cloud project name, and an internal reference to the project within the monorepo (for example, myorg_myproject_frontend).

Creating the projects of a monorepo

1. Select the ✚ (plus) menu on the top right of the SonarQube Cloud interface and select Analyze new project. The Analyze projects page opens.

2. Select Setup a monorepo (it is a small text link to the right of the Organization field). The Analyze monorepo projects page opens.

3. Select your organization and then choose the monorepo that you want to import. 

4. Select the Add new project button to create the first project. Review the proposed project name and key.

5. Proceed the same way for the other projects of the monorepo.

6. Once you’ve completed the project list, select the Save configuration button. The Set up project for Clean as You Code page opens.

7. Select the new code definition to be applied by default to the SonarQube Cloud projects in the monorepo. 

8. Select the Create projects button. 

Adding the SonarQube Cloud analysis to a monorepo's CI pipeline

To perform the configuration, follow the procedure for your CI service:

In the build procedure for each monorepo project, make sure to specify the SonarQube Cloud project key that you designated for it. This provides the binding between the project within the monorepo and the corresponding project in SonarQube Cloud. This enables SonarQube Cloud to correctly process the analysis results and to dispatch pull request decorations back to the DevOps platform for each project individually.


Was this page helpful?

© 2008-2024 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARQUBE, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License