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

**URL:** <https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321>\
**Category:** SonarQube Server / Community Build\
**Tags:** sonarjs, javascript\
**Created:** [June 18, 2018, 6:03pm UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321 "2018-06-18T18:03:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmaehr](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@bmaehr](https://community.sonarsource.com/u/bmaehr)\
**Post date:** [June 18, 2018, 6:03pm UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321/1 "2018-06-18T18:03:12Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![bmaehr](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@bmaehr](https://community.sonarsource.com/u/bmaehr)\
**Post date:** [June 18, 2018, 9:24pm UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321/2 "2018-06-18T21:24:06Z")

</div>

[testcase.zip.txt](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/1X/c77082750eda832b7e76a7bdb2e143a13c799167.txt) (1.5 KB)

---

<div class="post-metadata">

**Author:** ![bmaehr](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@bmaehr](https://community.sonarsource.com/u/bmaehr)\
**Post date:** [January 11, 2019, 5:40pm UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321/3 "2019-01-11T17:40:46Z")

</div>

Could someone please file this as bug?

---

<div class="post-metadata">

**Author:** ![Julien\_HENRY](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/julien_henry/32/61_2.png) [@Julien\_HENRY](https://community.sonarsource.com/u/Julien_HENRY)\
**Post date:** [January 14, 2019, 9:54am UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321/5 "2019-01-14T09:54:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bmaehr](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@bmaehr](https://community.sonarsource.com/u/bmaehr)\
**Post date:** [January 14, 2019, 10:42am UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321/6 "2019-01-14T10:42:48Z")

</div>

> 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

```

---

<div class="post-metadata">

**Author:** ![bmaehr](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@bmaehr](https://community.sonarsource.com/u/bmaehr)\
**Post date:** [March 14, 2019, 3:24pm UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321/8 "2019-03-14T15:24:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Julien\_HENRY](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/julien_henry/32/61_2.png) [@Julien\_HENRY](https://community.sonarsource.com/u/Julien_HENRY)\
**Post date:** [March 17, 2019, 2:46pm UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321/9 "2019-03-17T14:46:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bmaehr](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@bmaehr](https://community.sonarsource.com/u/bmaehr)\
**Post date:** [March 17, 2019, 3:30pm UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321/10 "2019-03-17T15:30:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lena](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/lena/32/66719_2.png) [@Lena](https://community.sonarsource.com/u/Lena)\
**Post date:** [April 2, 2019, 4:10pm UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321/12 "2019-04-02T16:10:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bmaehr](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@bmaehr](https://community.sonarsource.com/u/bmaehr)\
**Post date:** [April 2, 2019, 6:43pm UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321/13 "2019-04-02T18:43:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lena](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/lena/32/66719_2.png) [@Lena](https://community.sonarsource.com/u/Lena)\
**Post date:** [April 3, 2019, 6:57am UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321/14 "2019-04-03T06:57:03Z")

</div>

> - 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](https://github.com/SonarSource/SonarJS/issues/1222) on SonarJS analyser. In meantime you can use one of ideas I’ve suggested to workaround your problem.

---

<div class="post-metadata">

**Author:** ![bmaehr](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@bmaehr](https://community.sonarsource.com/u/bmaehr)\
**Post date:** [August 19, 2019, 4:45pm UTC](https://community.sonarsource.com/t/sonar-projectbasedir-doesnt-work-with-non-multi-module-projects/321/16 "2019-08-19T16:45:02Z")

</div>

@Lena Thank you for solving this, it works 🙂
