How to change Java version when running the docker image pulled from dockerHub

I am pulling SonarQube image from dockerHub through command
docker pull sonarqube
And using below command to run the container.

$ docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest

SonarQube is running fine, but it uses Jdk 11 to run it. I want to force docker to run qube on jdk 1.8

Can anyone help me to change jdk to run the container with external image and specific jdk ?

Hi @pravin and welcome to the community :wave:

Sonarqube requires Java 11 in order to run. It does not run on Java 8 as stated in the requirements here: Prerequisites and Overview | SonarQube Docs

Hope that helps

1 Like

This is helpful! Thank you @DefinitelyNotTobi

I have SQ running on docker and I wanted to scan my project but getting below error when running the scan.

Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin: failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin: java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.sonarsource.scanner.maven:sonar-maven-plugin:
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/Users/mwh581/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/
[ERROR] urls[1] = file:/Users/mwh581/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
[ERROR] urls[2] = file:/Users/mwh581/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[3] = file:/Users/mwh581/.m2/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar
[ERROR] urls[4] = file:/Users/mwh581/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/

Hi @pravin ,

In addition to requiring Java 11 to run SonarQube, you also must scan your project with Java 11 or Java 17 (but you can build with a different version of Java). Please see Scanner Environment | SonarQube Docs.

Thanks for your reply @Joe.
Here are the steps that I followed.

  1. I build my project with Java 8 - mvn clean install (it was successful)
  2. I set the JAVA_HOME to jdk 17
  3. executed the mvn verify sonar:sonar -Dsonar.login=token command to scan the project.

I am getting below error.
Corrupted STDOUT by directly writing to native stream in forked JVM 1.

[ERROR] Process Exit Code: 134
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(
[ERROR]         at
[ERROR]         at
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(
[ERROR]         at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(

Hi @pravin ,

Can you please show your entire pipeline or set of commands you are running and the debug Maven logs (add -X to the mvn command: mvn verify -X sonar:sonar ...)?

I am doing this locally, SQ is running on docker. The docker is installed locally.

Here are the commands I am executing.

  1. mvn clean install
  2. % echo $JAVA_HOME
  3. /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
    mvn verify -X sonar:sonar -Dsonar.login=<token>

Getting below error

Corrupted STDOUT by directly writing to native stream in forked JVM 1. Stream 'FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed'
# Created at 2022-08-01T17:58:06.564
Exception in thread "main" java.lang.reflect.InvocationTargetException

# Created at 2022-08-01T17:58:06.565
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

# Created at 2022-08-01T17:58:06.565
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(

# Created at 2022-08-01T17:58:06.565
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(

# Created at 2022-08-01T17:58:06.565
	at java.base/java.lang.reflect.Method.invoke(

# Created at 2022-08-01T17:58:06.566
	at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(

# Created at 2022-08-01T17:58:06.566
	at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(

# Created at 2022-08-01T17:58:06.566
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.

# Created at 2022-08-01T17:58:06.566
	at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(

# Created at 2022-08-01T17:58:06.567
	at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(

# Created at 2022-08-01T17:58:06.567
	at org.jacoco.agent.rt.internal_6da5971.PreMain.createRuntime(

# Created at 2022-08-01T17:58:06.568
	at org.jacoco.agent.rt.internal_6da5971.PreMain.premain(

# Created at 2022-08-01T17:58:06.568
	... 6 more

# Created at 2022-08-01T17:58:06.568
Caused by: java.lang.NoSuchFieldException: $jacocoAccess

# Created at 2022-08-01T17:58:06.568
	at java.base/java.lang.Class.getField(

# Created at 2022-08-01T17:58:06.568
	at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(

# Created at 2022-08-01T17:58:06.569
	... 9 more

# Created at 2022-08-01T17:58:06.569
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at open/src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 422

# Created at 2022-08-01T17:58:06.569
/bin/sh: line 1: 29972 Abort trap: 6           /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home/bin/java '-javaagent:/Users/mwh581/.m2/repository/org/jacoco/org.jacoco.agent/,excludes=org.jbpm.*:org.kie.*' -Xmx256m -jar /Users/mwh581/work/workspace/deposits-applications/deposits-applications-model/target/surefire/surefirebooter3803532677053084259.jar /Users/mwh581/work/workspace/deposits-applications/deposits-applications-model/target/surefire 2022-08-01T17-58-05_026-jvmRun1 surefire10904304984354787205tmp surefire_012456621198072059540tmp

This error looks like an issue with your usage of Java for your application. This has nothing to do with SonarQube or the Sonar scanner. Are you using the latest version of Jacoco? Make sure to update all your dependencies or build tools as necessary since you are using Java 17.

Please run mvn clean verify -X and check that there are no errors first. If you get no errors, then add the sonar:sonar goal.

For more hints about this issue, please see these links:

Late in the party, but in case someone else need it:
You don’t need to run verify goal when you are running sonar scan with jdk 11/17
Because, mvn verify will trigger compile/test phases and that will require jdk 8
With JDK 8, you run mvn verify
and then switch to JDK 11/17, then run mvn sonar:sonar -Dsonar.login=…

1 Like