sonar.projectBaseDir doesn't work with non-multi-module projects

sonar-maven-plugin:3.4.0.905:sonar

When building a not multi module project with maven the configuration sonar.projectBaseDir is ignored and the build direcory is always taken as project base dir. It works correctly with multi module projects.

This is a problem for example using lcov, because the paths of the lcov file are always expected to be from the sonar.projectBaseDir.

[code]
[INFO] 19:46:56.340 Analysing [/mnt/jenkins/workspace/nightly/target/coverage/lcov.info]
[WARNING] 19:46:56.347 Could not resolve 309 file paths in [/mnt/jenkins/workspace/nightly/target/coverage/lcov.info], first unresolved path: app/resolver.js

[code]

testcase.zip.txt (1.5 KB)

Could someone please file this as bug?

Hi @bmaehr,

I fail to understand your issue. If your project is not a multi module project, then you have a single pom.xml at the root of your project. And I guess you run mvn sonar:sonar in the same directory? Why would you like to change the value of sonar.projectBaseDir?
Your reproducer is a multi-module project, but you say that the issue is with simple projects, some Iā€™m a bit lost.

Can you elaborate?

Why would you like to change the value of sonar.projectBaseDir ?

Because it is necessary for the code coverage with lcov if the sources of JavaScript are not in the root folder of the project. Example: You put your sources to the folder src/main/ember. In the generated lcov file the paths are relative to src/main/ember. Sonar is only able to process the file correctly, if the sonar.projectBaseDir is set to src/main/ember

Your reproducer is a multi-module project, but you say that the issue is with simple projects, some Iā€™m a bit lost.

If you start the build of the project in the root of the testcase you have a multi module project, if you start the build in the sub folder, you have a non-multi-module project.

C:\projects\tmp>mvn sonar:sonar
[INFO] Project key: test:parent
[INFO] Project base dir: C:\projects\tmp
[INFO] -------------  Scan test
[INFO] Base dir: C:\projects\tmp\sub\src\main\ember
[INFO] Working dir: C:\projects\tmp\sub\target\sonar
[INFO] Source paths: C:\projects\tmp\sub\pom.xml


C:\projects\tmp\sub>mvn sonar:sonar
[INFO] Project key: test:test
[INFO] Project base dir: C:\projects\tmp\sub
[INFO] -------------  Scan test
[INFO] Base dir: C:\projects\tmp\sub
[INFO] Working dir: C:\projects\tmp\sub\target\sonar

@Julien_HENRY Any news on this? Should be easy to fix.

Hi @bmaehr

To me the issue should be fixed in our lcov importer, but Iā€™m waiting for opinion of my colleagues on this. Changing the project baseDir ā€œjustā€ for the coverage is a mistake in my opinion, and may have many other side effects.

Hi @Julien_HENRY,

You are right that it is only some kind of workaround and the lcov importer should be improved.

I also donā€™t expect, that the baseDir should be changed generally because of the reasons you mentioned.

But when I explicitly configure the baseDir using the provided property I expect, that my configuration is honored.

Hi @bmaehr

Indeed our LCOV parser expects either an absolute path or a relative to the project base directory. When paths in your LCOV file are relative to something else, how LCOV parser can know what is this ā€œsomething elseā€?

I would suggest you two things:

  • see if your coverage tool can generate report with absolute paths
  • write a small script which will prefix all paths in your report with appropriate path (e.g. src/main/ember in your example), and run it before running analysis.

Hello @Lena

how LCOV parser can know what is this ā€œsomething elseā€?

  • The parser could provide a property to configure that like suggested by Julien
  • The sonar-maven-plugin could be fixed to honor the configuration of sonar.projectBaseDir like suggested by me in this thread
  • The parser could provide a property to configure that like suggested by Julien

I think you misinterpret what Julien said, he only pointed that this problem should be fixed in the context of lcov importer.

  • The sonar-maven-plugin could be fixed to honor the configuration of sonar.projectBaseDir like suggested by me in this thread

I think you are missing the fact that base dir of project not only used to resolve relative paths in LCOV report but also to define base dir of the project:) So I expect that changing it to your JS dir will force analysis to ignore other files in your module.

Iā€™ve created a ticket on SonarJS analyser. In meantime you can use one of ideas Iā€™ve suggested to workaround your problem.

1 Like

@Lena Thank you for solving this, it works :slight_smile: