使用 sonar gradle 插件扫描 Java 8 Spring boot 项目以获取 sonarqube,但它需要 java 11

PSK*_*SKP 5 java gradle sonarqube

我的项目使用 java 8 和 sonarqube 插件id 'org.sonarqube' version '2.6.2'。当我使用 command 构建项目时./gradlew clean build,它构建得很好。

但是当我尝试运行时./gradlew sonarqube,出现错误

* 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
Run Code Online (Sandbox Code Playgroud)

我的声纳任务看起来像什么

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"
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试过的

我尝试了这个答案Run SonarScanner Analysis with Java 11, run target code with Java 8

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"
    }
}
Run Code Online (Sandbox Code Playgroud)

然后出现以下错误

* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
> Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().
Run Code Online (Sandbox Code Playgroud)

编辑

我的公司使用 gitlab runner 并使用 openjdk 8,sonarqube 工作正常。我不知道怎么办?我还附加了 dockerfile。可能有人会理解为什么它在那里工作而不是在我的机器上工作。

我删除了一些敏感部分

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"]
Run Code Online (Sandbox Code Playgroud)

PSK*_*SKP 0

我使用的是最新的 sonarqube,它需要 Java 11。我切换到 Sonarqube 8,现在唯一的警告来了。

在此输入图像描述

如果您正在使用 docker sonarqube 尝试使用sonarqube:lts