Why does sonar-scanner force the usage of the embedded JRE?


Why does sonar-scanner force the usage of the embedded JRE?
See below extract from the latest version downloaded from https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner:

if [ "$use_embedded_jre" = true ]; then
  export JAVA_HOME=$sonar_scanner_home/jre

Even stranger, when downloaded from Maven central (https://search.maven.org/remotecontent?filepath=org/sonarsource/scanner/cli/sonar-scanner-cli/, the code is different…

if [ "$use_embedded_jre" = true ]; then
  export JAVA_HOME=$sonar_scanner_home/jre

Thank you



Hi David,

The are multiple flavours distributed on this page. Notably the Windows/Linux/Mac ones that do have an embedded JRE, and that’s on purpose to facilitate adoption/usage.

The Any flavour is the one that doesn’t have an embedded JRE, as clearly stated:

*This package expects that a JVM is already installed on the system - with same Java requirements as the SonarQube server.

1 Like

Thanks for the quick reply Nicolas!
My apologies for not noticing the comment…

Thanks for the clarification. Please note though, that in the top of the sonar-scanner script, it does clearly say:

# Optional ENV vars:
# JAVA_HOME - Location of Java’s installation

It requires very careful reading of the full source to understand that this line:


effectively disables all the following logic to figure out a suitable JAVA_HOME, including causing the existing environment variable to be ignored and overridden.

Perhaps this in-script documentation can be corrected to reflect this behaviour. The solution for me is indeed quite simple: just download the “Any” flavour. It’s just that this way it took a good amount of time to figure that out.

Hi Erik,
I’ve created a ticket so that we fix the documentation on top of the script: https://jira.sonarsource.com/browse/SQSCANNER-70

@elogtenberg - Made an account here just to say thank you.

I was able to use your info to fix our issue. For now, went with a find-and-replace change in our Dockerfile. Here’s the relevant snippet:

sed -i.bak \
's/use_embedded_jre=true/use_embedded_jre=false/g' \

And now the JAVA_HOME we previously set is respected :slightly_smiling_face: