- which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension): Sonarqube 10.5, Maven Sonar Plugin 4.0.0.4121
- how is SonarQube deployed: zip
- what are you trying to achieve: I want to scan merge requests, but only the module that has been changed
- what have you tried so far to achieve this:
I feel that it’s necessary for me to describe my current situation before I’m telling you about what I’ve already done about it.
My license type is Enterprise. So I have a large monorepo project with about 400k LoC and 10+ modules with a lot of submodules inside of each one. So I have 1 “root” pom.xml and for each module and submodule I have its own separate pom.xml which inherits some properties from the root one.
When I try to scan the project, including scans triggered by Merge requests (I use Gitlab CI), it usually takes a lot of time, anywhere between 8-12 minutes.
This scan time is unacceptable to us because it takes more time than building and deploying the whole project from scratch.
I figured that I can detect which module has been changed, and scan this exact module/submodule to reduce scanning time. The problem is, when I try to do this, I encounter an error.
- I have tried pointing mvn to the desired (changed) module’s directory by using “-pl” flag for the mvn command while pointing mvn to the “main” pom.xml via “-f”
- I have tried pointing mvn to the desired (changed) module’s directory by using “-f” flag without using “-pl”
- I have tried just “cd desired/module/directory” before doing mvn command (without -f or -pl)
This is an example of script section of my gitlab-ci pipeline which I use to scan the project:
script:
- echo $path
- cd $path
- "mvn sonar:sonar
-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository \
-Dsonar.qualitygate.wait=true \
-Dsonar.projectName=monorepo-name_$module_name \
-Dsonar.projectKey=$module_name \
-Dsonar.java.binaries=$CI_PROJECT_DIR/.m2/repository \
-Dsonar.pullrequest.key=$CI_MERGE_REQUEST_IID \
-Dsonar.pullrequest.branch=$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME \
-Dsonar.pullrequest.base=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME \
-Dmaven.test.skip=true \
-Dsonar.exclusions=**/*.sql"
Everything leads to a singular error which prevents me from scanning my modules:
“[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:4.0.0.4121:sonar (default-cli) on project module_name: Maven session does not declare a top level project → [Help 1]”
Can you guide me on how to do this?