Source files are ignored because they are outside of project basedir

  • which versions are you using (SonarQube Server / Community Build, Scanner, Plugin, and any relevant extension)

sonarqube-10.5.1.90531
SonarScanner CLI 6.2.1.4610

  • how is SonarQube deployed: zip, Docker, Helm

zip

  • what are you trying to achieve

I want to analyze the project that has some files outside of project basedir.

  • what have you tried so far to achieve this

Played with different combinations of sonar.baseDir and sonar.sources parameters.

My directory structure is like this:

D:\foobar\common\
    D:\foobar\common\helloworld.cpp
    D:\foobar\common\something.cpp
D:\foobar\Foo\
    D:\foobar\Foo\Foo.sln
    D:\foobar\Foo\Bar
        D:\foobar\Foo\Bar\Bar.vcxproj
        D:\foobar\Foo\Bar\sonar-project.properties

The file helloworld.cpp is added into the Bar project using Visual Studio (Right click ā†’ Add ā†’ Existing itemā€¦)

My sonar-project.properties file:

sonar.projectKey=my_example_Bar
sonar.projectName=MY example Bar
sonar.sources=.,D:\\foobar\\common
sonar.cfamily.build-wrapper-output=build-wrapper-output-directory
sonar.projectVersion=1.0

I build the project using this command:

build-wrapper-win-x86-64.exe --outdir D:\foobar\Foo\Bar\build-wrapper-output-directory MSBuild.exe D:\foobar\Foo\Bar\Bar.vcxproj /t:Rebuild /p:Platform=x86 /p:Configuration=Release /nodeReuse:False

Then I execute ā€œsonar-scannerā€ inside the project directory D:\foobar\Foo\Bar.

In the output I see the message that the helloworld.cpp file will not be analyzed.

File ā€˜D:\foobar\common\helloworld.cppā€™ is ignored. It is not located in project basedir ā€˜D:\foobar\Foo\Barā€™.

Why doesnā€™t sonarqube allow files outside of project base dir?

In my case I really canā€™t set the baseDir to D:\foobar\common\ because Iā€™m trying to analyze the D:\foobar\Foo\Bar\ project. D:\foobar\common\ directory is not a project at all and these files would be used by multiple projects. So this solution for example does not work for me: Sonar-scanner don't find source files

Is there anything else I can do to analyze this project correctly?

Hey there.

It seems like you really want to execute the sonar-scanner from the D:\foobar\ directory (the root directory of all the code you want to analyze), and then set sonar.sources to the directories you want to analyze (Foo/Bar,common).

Yeah thatā€™s exactly what I donā€™t want to do. This would analyze everything under D:\foobar\ which is not what I want. Not all files there belong to this project.

If you set sonar.sources, you will only analyze what is in those folders. You just need the base directory (where the scanner is executed) to be the parent of all those directories.

1 Like

I fixed this by scanning the vcxproj file, parsing all source files paths and adding them to sonar.sources comma separated. I create a sonar-project.properties on the fly at the directory where Iā€™m running sonar-scanner from.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.