which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension) Roshni - SonarQube version: 7.9.1
what are you trying to achieve Roshni - We have maven multi module project where all the java code resides in parent project source folder(src/main/java) and child module refers to the parent source code.
while running sonar scanner on the parent project, it skips the parent source code and looks for child module basedir which leads to[WARNING] File is ignored. It is not located in module basedir.
No java files are getting scanned with message “The main branch of this project is empty.”
what have you tried so far to achieve this
I have tried below options.
Adding CLI property to parent project : " -Dsonar.sources=src\main\java"
This fails as it looks for the source in child module and some of the child module do not have source code.
Adding CLI property to parent project : “-Dsonar.projectBaseDir=src\main\java”
This doesnt fail but still skips the source code from parent folder.
Adding sonar-project.properties to add source in Child modules - “sonar.sources=…\src\main\java”
Same result, skips the code from parent source code.
Adding sonar-project.properties to add source to Parent module.
Still skips the source java files. I couldnt find entry in log to assure that the properties were successfully read from properties file.
Please assist in fixing this issue.
Please note - The project maven structure is designed in to support reverse code dependencies to avoid code duplication across child modules as the child modules refers to some common classes and are interdependent.
Hi,
Could you give more details on the layout of the project? How is the child module referring to the parent’s source code?
How are you running the mvn goal?
Scanner logs could be useful too.
There are a few notes about this particular setup:
Setting a property in the command line (with -D...) will set it for all modules. This is usually not what is intended.
It’s not possible to add source code to Modules of type pom. Anyway if it was possible, it wouldn’t work correctly. Java source code needs to be analyzed in a certain context with the a classpath and bytecode, and this wouldn’t be available in that module.
SonarQube offers a view over the entire project (all modules) so it’s not possible to include the same files in different Maven modules
With this in mind, the only option I see is to add ParentProject/src/main/java to one of the child projects.
This can be done by adding, for example in Child_Module1/pom.xml:
You can try to not define sonar.sources and see if it picks up sourceDirectory correctly, if it doesn’t you can override it like that and add other sources within the module.
Hi Duarte,
Thank you, adding <sonar.projectBaseDir> worked, however it led me to couple issues with code duplicates. I had to add excludes in Parent project to make it work.