[WARNING] File is ignored. It is not located in module basedir

Must-share information (formatted with Markdown):

  • 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.

  1. 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.
  2. Adding CLI property to parent project : “-Dsonar.projectBaseDir=src\main\java”
    This doesnt fail but still skips the source code from parent folder.
  3. Adding sonar-project.properties to add source in Child modules - “sonar.sources=…\src\main\java”
    Same result, skips the code from parent source code.
  4. 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.

Hello,
Please confirm if the feature to scan source folders outside the base project directory is available.
Thanks in advance.

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.

Thanks for responding, appreciate your help.

We are using maven build for project, this is our project structure for some projects
ParentProject

|_
   src/main/java
|_
 Child_Module1
       |_  Calling parent project src/main/java
|_
  Child_Module2
       |_   Calling parent project src/main/java  
|_
  Child_Module3 
       |_ Calling parent project src/main/java

We have configured child modules pom to use parent source through

   <build><sourceDirectory>../src/main/java</sourceDirectory></build>

mvn command with projectBaseDir-
mvn install sonar:sonar -Dsonar.projectKey=<ParentProject_key> -Dsonar.host.url=<sonar_server_url> -Dsonar.login=<login_cred> -Dsonar.projectBaseDir=src/main/java
mvn command with sonar.sources-
mvn install sonar:sonar -Dsonar.projectKey=<ParentProject_key> -Dsonar.host.url=<sonar_server_url> -Dsonar.login=<login_cred> -Dsonar.sources=src/main/java

I also tried to do the same with sonar-project.properties, didnt work either.

I wont be able to share the logs as is, company confidentiality policies.
But here is how it looks like

[INFO] Process project properties
[INFO] Execute project builders
[INFO] Execute project builders (done) | time=7ms
[INFO] Project key:
[INFO] Base dir: <absolute_ParentProject_dir>
[INFO] Working dir: <absolute_ParentProject_dir>\target\sonar
[INFO] Load project settings for component key: ‘<ParentProject_key>’
[INFO] Load project settings for component key: ‘<ParentProject_key>’ (done) | time=1007ms
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=1086ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=16281ms
[INFO] Indexing files…
[INFO] Project configuration:
[INFO] Indexing files of module ‘ChildModule1’
[INFO] Base dir: <absolute_ParentProject_dir><ChildModule1>
[INFO] Source paths: pom.xml
[WARNING] File ‘<absolute_ParentProject_dir>\src\main\java**.java’ is ignored. It is not located in module basedir ‘<absolute_ParentProject_dir><ChildModule1>’.

going through each src/main/java files, skipping them all eventually giving false positive result.

Thanks, that helps me understand the problem.

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:

<properties>
    <sonar.projectBaseDir>..</sonar.projectBaseDir>
    <sonar.sources>../src/main/java,pom.xml</sonar.sources>
</properties>

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.

Appreciate your help on this :slight_smile: