My project is using java 8 and sonarqube plugin id 'org.sonarqube' version '2.6.2'
. When I build project using command ./gradlew clean build
, it builds fine.
but when I try to run ./gradlew sonarqube
, I get error
* What went wrong:
Execution failed for task ':sonarqube'.
> 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
My sonarqube task looks like something
sonarqube {
properties {
properties["sonar.analysis.mode"] = "publish"
properties["sonar.projectKey"] = System.getenv("SONAR_PROJECT_KEY").toString().trim()
properties["sonar.projectName"] = System.getenv("SONAR_PROJECT_NAME").toString().trim()
properties["sonar.host.url"] = System.getenv("SONAR_HOST").toString().trim()
properties["sonar.login"] = System.getenv("SONAR_TOKEN").toString().trim()
properties["sonar.branch.name"] = System.getenv("CI_COMMIT_REF_NAME").toString().trim()
switch(System.getenv("CI_COMMIT_REF_NAME").toString().trim()) {
case ~/^feature\/MDS-.*$/:
properties["sonar.branch.target"] = "develop"
break
case 'master':
case 'develop':
break
default:
properties["sonar.branch.target"] = "master"
break
}
properties["sonar.exclusions"] = "**/analytics/model/**/*.java"
properties["sonar.coverage.exclusions"] = "**/analytics/model/**/*.java"
}
}
What I tried
I tried this answer Run SonarScanner analysis with Java 11, run target code with Java 8
# build successful
./gradlew clean build
# change to java 11
$env:JAVA_HOME="C:\Users\wv3cxq\Downloads\jdk-11.0.12_windows-x64_bin\jdk-11.0.12"
# Tried to run sonarqube task
./gradlew sonarqube
Then getting following error
* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
> Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().
Edit
My company uses gitlab runner and with openjdk 8, sonarqube is working fine. I don't know how? I am attaching dockerfile also. May be someone will understant why it is working there and not on my machine.
I removed some sensitive part
FROM alpine:3.7
ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/bin/
RUN apk --no-cache update && \
apk --no-cache add \
openjdk8=8.171.11-r0 \
docker=17.12.1-r0 \
&& \
pip --no-cache-dir install docker-compose==1.22.0 awsebcli==3.7.8 && \
rm -rf /var/cache/apk/*
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["sh"]