java - 使用 sonar gradle 插件扫描 Java 8 Spring Boot 项目的 sonarqube,但它需要 java 11
问题描述
我的项目正在使用 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
我的声纳任务看起来像什么
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 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
然后出现以下错误
* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
> Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().
编辑
我的公司使用 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"]
解决方案
推荐阅读
- docker - Kubernetes - 我的 2 个应用程序部署仅在一个“参数”中有所不同 - 我可以拥有将引用它们的服务吗?
- reactjs - React 和 redux 使用异步数据获取
- java - 如何反向打印堆栈?
- html - 如何在带有溢出的父元素外部显示下拉菜单:CSS中的自动?
- swift - SwiftUI:重置 TabView
- javascript - React组件中如何使用reduce计算总量?
- r - 使用 R 和 XML 解析国家气象服务数据时遇到问题
- postgresql - Hypersistence Micronaut Postgres 日期范围问题
- javascript - 如何获取网站的 javascript 代码?
- python - GRAPHVIZ:无法执行 ['dot', '-Kdot', '-Tsvg'],请确保 Graphviz 可执行文件位于您系统的路径中