How to add new project to monorepo

I set up a monorepo in Sonarqube Cloud by following the official guide.

Initially I set up with 6 projects that were under my monorepo. All worked perfectly.

Fast forward a week, I now have a seventh project inside my monorepo that I want to add to my existing monorepo that I created. But I am not able to find any obvious place in the UI that allows you to do that.

Any help would be much appreciated, thank you!

You’re right, it’s not super obvious, but you just need to follow process as you did when you created the initial 6 projects.

After clicking “Setup a monorepo” in the Analyze new projects portal, select your repository and continue to add new projects!

If I click “Add new project” – those projects created will be bound to the monorepo, like the other 3 I already linked to this repo (colin-sonarsource_test-repo-java, colin-sonarsource_test-repo-java_1, colin-sonarsource_test-repo-java_2)

Thank you very much, Colin. It was that easy!

Just one further observation. My information box doesn’t show all linked projects like in your screenshot. It just shows one of them i.e. it says “Repository already imported and linked to the xyz project on SonarQube Cloud” where xyz is an arbitrary repository of those 6 I initially linked.

This is weird because each one of those 6 Sonar projects seems to work perfectly fine.

I thought it was a small bug of SonarCloud but now your screenshot baffled me.

That’s weird.

The results of the API call come from https://sonarcloud.io/api/alm_integration/list_repositories?organization=ORG_KEY. Do you only see the one linked project for the repo in question? Do you see those projects anywhere else in the response?

Yes, only that one single repo at the linkedProjects key of my monorepo item.

And no, I can’t see any of the other projects anywhere else in the whole response.

Yet, I can browse them and they work as expected.

So even the one you just added doesn’t appear?

So even the one you just added doesn’t appear?

As I add a new repo, that becomes the only repo that the UI and the API show as linked. All others are not shown.

Thank you. What DevOps Platform are you using? GitHub, GitLab, Azure DevOps, Bitbucket…

We build via Gradle (we run the sonar scanner via the Sonarqube gradle plugin).

I think that’s what you were asking, but just for the sake of completeness: the gradle command itself (we use the gradle wrapper) is run as part of a Jenkins stage (via an sh step). The Jenkinsfile, wrapper and build scripts are all in the git monorepo in Bitbucket (which we use only as a VCS).

In the monorepo we have a multi-project Gradle build, each subproject declares its own sonar.projectKey property under sonarqube { properties { } }.

Hey @vaklam2!

Bitbucket was what I was looking for. And indeed, I can reproduce the behavior with Bitbucket (I could not with GitLab or or GitHub) when going back to add more proejcts to an existing repo I’ve provisioned as a monorepo with multiple projects.

So this looks like clearly a bug on our side. I’ve flagged it for attention.

Cool, glad I contributed somehow!

1 Like