Set cache location for sonar-scanner

Currently sonar-scanner always use ~/.sonar/cache as cache directory (along with .scannerwork). It does makes sense to cache both of those directories for CI/CD pipelines, but most of them does not allow to cache directories outside of working dir.

It would be great to have an option to set cache location like so:

sonar-scanner -Dcache=.cache

Hi

you’re right, it seems this option is missing.
Sonarlint has such an environment variable = SONARLINT_USER_HOME
For Sonar scanner i only know SONAR_SCANNER_HOME and SONAR_SCANNER_OPTS
If there ain’t a similar environment variable for Sonar scanner you might use a symbolic link !?

Gilbert

Hi,

You can use SONAR_USER_HOME. This will change location of ~/.sonar.

Hi @Julien_HENRY,

is this mentioned in Sonarqube documentation, didn’t find an entry ?

Gilbert

Hi @Julien_HENRY Julien, I’ve tried this in the jenkins slave but doesn’t seem to work is there any other way to change the cache location? Please suggest.Thanks!

@Julien_HENRY @Chris @Fabrice_Bellingard @anon67236913 @Mike_Birnstiehl @sushmavh
in Azure devops also same problem. The .sonar/_cache is getting creatd in /home/user directory where we dont have enough space. Not sure how to change this location from our sonarqube task pipeline yaml

I am trying the sonar runner in Bamboo and I have found this exact problem as well. Nothing I can set will change the location of the cache directory.