Start FreeLog in
SonarCloud | Advanced setup | Monorepo support

Was this page helpful?

Monorepo support

On this page

SonarCloud 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, SonarCloud's support for the monorepo strategy does not depend on the specifics of the monorepo setup. SonarCloud 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 SonarCloud project.

Setting up the analysis of a monorepo

In a standard setup, each SonarCloud project corresponds to a single repository. In a monorepo setup, multiple SonarCloud 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 SonarCloud that appears in the pull request view is clearly distinguished by project name. 
  • The monorepo associated with a project is shown in the SonarCloud 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 SonarCloud in order to create the monorepo projects in SonarCloud. 
  2. Add the SonarCloud analysis to your monorepo's CI pipeline.

Note that each SonarCloud project must have a key unique across SonarCloud (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 SonarCloud project. We recommend using a pattern that includes your organization name, the SonarCloud 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 SonarCloud 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 SonarCloud projects in the monorepo. 

8. Select the Create projects button. 

Adding the SonarCloud 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 SonarCloud project key that you designated for it. This provides the binding between the project within the monorepo and the corresponding project in SonarCloud. This enables SonarCloud to correctly process the analysis results and to dispatch pull request decorations back to the DevOps platform for each project individually.

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

Creative Commons License