3

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"]
PSKP
  • 1,178
  • 14
  • 28
  • 1
    Java 8 went end of support January 2019, and the current version is 17! For *lots* of good reasons, you should upgrade your java version. – Bohemian Sep 26 '21 at 12:28
  • Instead of just setting $JAVA_HOME at that point, try adding $JAVA_HOME/bin to the head of the PATH. – David M. Karr Sep 26 '21 at 14:57
  • 1
    @bohemian, actually, [Oracle announced](https://www.infoworld.com/article/3532358/oracle-extends-extended-support-for-java-8.html) extended support for JDK8 to [at least Dec 2030](https://www.oracle.com/java/technologies/java-se-support-roadmap.html) and OpenJDK has support to [at least May 2026](https://adoptopenjdk.net/support.html). Due to widespread corporate use, it will outlive 11 and maybe 17! Anything in between (I'm non-lts) is now deprecated and EOL. – Ian W Sep 30 '21 at 08:47
  • 1
    Have you found a solution to your problem because I encounter the same thing – dna Oct 09 '21 at 23:32
  • @dna still not. – PSKP Oct 10 '21 at 05:22
  • I am now using `sonarqube:lts` docker image and it is working. It just gives a warning but it works. – PSKP Jun 24 '22 at 15:42

1 Answers1

0

I was using the latest sonarqube which requires Java 11. I switched to Sonarqube 8 and now the only warning is coming.

enter image description here

If you are using docker sonarqube try using sonarqube:lts

PSKP
  • 1,178
  • 14
  • 28