Hello! Is there a way to change the location of the cache directory? We are using sonarqube-scanner v4.3.2.
For context, we are using Nx to scan multiple JS/TS Sonar projects in a monorepo. We are trying to parallelise the scans, but it seems like it’s not possible because all the scans are using the same cache directory:
Error: EACCES: permission denied, open '/home/runner/.sonar/cache/
We are running the nx command from the root of the monorepo, and have a sonar command set for every project. In CI, we then run nx affected -t sonar.
This is what I expected as I only set sonar.working.directory.
The relevant part is this I believe:
[DEBUG] Bootstrapper: Looking for Cached JRE
[INFO] Bootstrapper: No Cache found for JRE
[DEBUG] Bootstrapper: Creating Cache directory as it doesn't exist: /home/runner/.sonar/cache/bcb1b7b8ad68c93093f09b591b7cb17161d39891f7d29d33a586f5a328603707
[DEBUG] Bootstrapper: Starting download of JRE
[DEBUG] Bootstrapper: Downloading https://scanner.sonarcloud.io/jres/OpenJDK17U-jre_x64_linux_hotspot_17.0.11_9.tar.gz to /home/runner/.sonar/cache/bcb1b7b8ad68c93093f09b591b7cb17161d39891f7d29d33a586f5a328603707/OpenJDK17U-jre_x64_linux_hotspot_17.0.11_9.tar.gz
[DEBUG] Bootstrapper: Not using axios instance for https://scanner.sonarcloud.io/jres/OpenJDK17U-jre_x64_linux_hotspot_17.0.11_9.tar.gz
[INFO] Bootstrapper: Download starting...
[INFO] Bootstrapper: Download complete
[INFO] Bootstrapper: Downloaded JRE to /home/runner/.sonar/cache/bcb1b7b8ad68c93093f09b591b7cb17161d39891f7d29d33a586f5a328603707/OpenJDK17U-jre_x64_linux_hotspot_17.0.11_9.tar.gz
[DEBUG] Bootstrapper: Verifying checksum bcb1b7b8ad68c93093f09b591b7cb17161d39891f7d29d33a586f5a328603707
[ERROR] Bootstrapper: An error occurred: Error: ENOENT: no such file or directory, open '/home/runner/.sonar/cache/bcb1b7b8ad68c93093f09b591b7cb17161d39891f7d29d33a586f5a328603707/OpenJDK17U-jre_x64_linux_hotspot_17.0.11_9.tar.gz'
The SonarQube scan failed for project 'client'
Error: ENOENT: no such file or directory, open '/home/runner/.sonar/cache/bcb1b7b8ad68c93093f09b591b7cb17161d39891f7d29d33a586f5a328603707/OpenJDK17U-jre_x64_linux_hotspot_17.0.11_9.tar.gz'
I believe this is because my projects are running in parallel and the sonar.userHome is still /home/runner/.sonar for all projects so they all modify the same /home/runner/.sonar/cache folder.
I’ve set the parameter via the sonarqube-scanner API to be {projectRoot}/.scannerwork. The value shown in the logs is expected as the project root in that case is apps/client
We’re using the https://www.npmjs.com/package/sonarqube-scanner package so no sonar-project.properties. But as I said, I can see in the logs that the value I passed is correctly picked up. I think my initial question still stands and it’s how to change the directory for the cache folder. What is the expected behaviour when setting sonnar.working.directory?
According to the docs for sonnar.working.directory:
Path to the working directory used by the SonarScanner during a project analysis to store temporary data. This property is not compatible with the SonarScanner for .NET.
The path can be relative (to the sonar.projectBaseDir property) or absolute. It must be unique for each project.
So it does work imo. What I am asking is how to change the cache directory, which based on the docs it doesn’t seem expected to work only by setting sonnar.working.directory. I’ve found this SONAR_USER_HOME in SonarScanner CLI | SonarQube Server | Sonar Documentation , but can’t find any other reference of it so not sure if it’s safe to use and part of the public API?
I think the relevant logs are here pasted in this comment. There’s a lot of logs otherwise. If the ones I provided earlier aren’t helpful, let me know what from the logs you need.