Maybe I have to specify my question more clearly. I have to run the Maven@3 task with jdk 1.8 but the SonarScanner needs 1.11.
Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar (default-cli) on project : Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar: 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
I somehow have to set sonar.java.jdkHome=/usr/lib/jvm/jdk-11 for the scanner.
If I understand well, you need jdk8 to build your project and you need jdk11 to run SonarScanner.
If this is the case, then you are right to use sonar.java.jdkHome. You can build your project with jdk8. Then when executing analysis, you need to run SonarScanner with this property pointing to jdk8, i.e. sonar.java.jdkHome=/usr/lib/jvm/jdk-8.
I solved it with compiling in JDK8 and moving the sonar phase to another task with JDK 11. I just had issues when activating jacoco in the Maven@3 task which creates a VSTSReport but not the target/site folders.
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
jdkVersionOption: '1.8'
goal: clean package
# do not use jacoco here
- task: Bash@3
displayName: 'Run sonar:sonar'
inputs:
targetType: 'inline'
script: |
export JAVA_HOME=/usr/lib/jvm/jdk-11
mvn sonar:sonar
- task: SonarQubePublish@4
inputs:
pollingTimeoutSec: '400'