assuming you have a maven module with the following structure:
root module
integration test module
sources module A
sources module B
additional modules…
and you have a pipeline in jenkins which use multiple jobs as part of the build process: preliminary job that compile all modules, and then, additional job that runs the integrations test by executing a maven command on the integration tests module.
now, in sonarqube server, you would like to see all of the sources from all modules, and for each of them, the coverage data.
from what I understand, there are two ways to accomplish this, and the first way is preferable -
run an aggregation job to collect the data after integration test over.
we tried to configure the base directory property ( sonar.projectBaseDir ) as a maven parameter, pom property and in sonar-project.properties file. (also tried an absolute and relative paths)
no matter what we tried, it seems that the base folder is not affecting sonar. as you can see in the picture below (base dir), and by reviewing results in sonar server, the only files that we get are files that located inside integration-tests module (inner module). while we would like that the analysis will be done regarding all the files inside the parent module.
I don’t understand why you’re trying to override the project base directory. The SonaQube Scanner for Maven is set up to just work - one module or many. Have you tried simply cd-ing into your project root and running mvn sonar:sonar? Assuming your test executions put the reports in the normal places, they should be picked up.
Hey,
I am trying to override the base directory because the execution starts from an inner module (which run’s the tests for all outside modules).
I figured that sonar:sonar goal attached to one of the latest maven phases and therefore it will in turn require execution of some of the maven flow again. (as mentioned, before the sonar goal being executed, mvn clean install command already ran on the root module, and mvn integration-test phase already ran for the inner module).
are you suggesting that the right way collecting the coverage results and getting source files for all modules is running “mvn sonar:sonar” on the root after the integration tests are done?
(just want to emphasis here that the jacoco ‘exec’ files are only inside the integration test module (where all the tests sits).
I have the sense that these should be tucked into the target directories of the relevant code instead (altho I’m not sure about this), but in general, yes. The right way to run analysis is to execute mvn sonar:sonar from project root after your test reports have been generated.
The base directory configuration is only for extraordinary circumstances. I’ve had to use it before in analyzing COBOL code when the nightly FTP dump didn’t put it (for obvious reasons) into a Jenkins workspace and I didn’t want to bloat the filesystem by cp-ing it around.
tried to run the analysis from the root directory.
still having unexplained issues…if it’s better to open another thread for that, let me know.
i am getting “file can’t be index twice error”
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project yyy-server-root: File Server/query-translation/api/src/main/java/com/…/querytranslation/QueryToDqlCompilerOptions.java can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files -> [Help 1]
now, I have checked my configuration over and over and I don’t see overlapping between test and main files…
here are my sonar properties:
but anyway,
I tried few variations of inclusion / exclusion patterns, and they all failed.
f or example, as you can see in the following:
Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project yyy-root: File Server/yyy-dal-db-entity-platform/impl/src/main/java/com/…/dal/dbentityplatform/DalServiceBase.java can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files.
this is the excluded & included paths from the logs:
correct me if I am wrong, but the DalServiceBase.java file answer to the definition **/src/main/**/* which is included by sources (you can see in the picture above), and excluded by tests.
so it can’t be the case where this file is being indexed twice by test and main definitions, isn’t it ?