Hi!
I’m trying to run SonarQube for some applications inside a nx.dev monorepo (all are Node Serverless applications), but I can only get a single one to write the reports. This is what I’ve tried so far:
sonar.properties (I’ve added blank spaces for readability)
But only the second one generates its reports. So, I’m wondering: is there any way to run the tests (and then Sonar) for only some parts of the monorepo?
Does the Enterprise Edition supports this behavior?
Relevant versions are:
SonarQube: Community Edition - Version 9.2.4 (build 50792)
Sorry, but running your tests is outside the scope of this community.
Fortunately, SonarQube analysis is not.
The first step is to pick a different project key for each project in the monorepo, then pass it in to analysis with the correct properties to identify the isolated subset of code that corresponds to the project. And that you can do in any edition.
Hi Ann, thanks for your quick reply. How can I set different keys for different submodules? If I try to add two of them in my sonar-project.properties (which is placed at the root level of the monorepo), like this:
and then I add other sonar-project.properties files, one per project, then the last key is the one Sonar picks (which makes sense), and the whole monorepo gets analyzed (which is what I don’t want to happen). How should I pass the desired keys as parameters to the scanner?
You’re going to need a properties file per sub-project (presumably in a subdirectory…?). Or you’ll need to pass the properties in on the analysis command line using -Dproperty.name=value.
Hi,
I’ve tried to install (hopefully) the official scanner via Homebrew, and then I’ve run an analysis with
sonar-scanner -Dsonar.projectKey=insurance
where insurance is the projectKey I’ve defined in a subdirectory of the monorepo.
However, this seems to analyze the entire monorepo, rather than a specific subdirectory. I suspect this is the case, because inside code (for my project insurance) I can also see other subdirectories, which are the ones I’d like to exclude.
So, maybe these steps aren’t enough to analyze only parts of my monorepo? What could I be missing here?
Thanks!
Is sonar.projectKey the only parameter you provided? Is there perhaps a sonar-project.properties file with more? Because sonar.sources defaults to ., so if you launch analysis from project root without specifying a narrowed sonar.sources, then analyzing your entire project is the expected behavior.
You might take a look at the docs I linked. They give you the (real) official scanner download and some direction on getting started with analysis.