Java 如何配置声纳云
我有一个java项目,我想将其与SonarCloud集成,我遵循以下官方步骤: 使用声纳QUBE扫描仪检查代码# 在检查代码之前,您需要:Java 如何配置声纳云,java,encryption,sonarqube,travis-ci,sonarcloud,Java,Encryption,Sonarqube,Travis Ci,Sonarcloud,我有一个java项目,我想将其与SonarCloud集成,我遵循以下官方步骤: 使用声纳QUBE扫描仪检查代码# 在检查代码之前,您需要: 在云上为您的帐户创建用户身份验证令牌 加密此令牌travis Encrypt abcdef0123456789或在存储库设置中定义SONAR_令牌 找到您希望推进项目的SonarCloud.io组织并获取其密钥 为您的项目创建sonar-project.properties文件(请参阅文档)。然后将以下行添加到.travis.yml文件中 要触发分析,请执行
addons:
sonarcloud:
organization: "xelian-github"
token:
secure: ${SONAR_TOKEN}
branches:
- master
script:
# other script steps might be done before running the actual analysis
- sonar-scanner
其中SONAR_TOKEN是Travis CI上的一个变量,指向SonarCloud中的密钥(未加密)。
我从云添加权限
但当我启动travis构建时,我有以下错误:
Setting environment variables from repository settings
$ export SONAR_TOKEN=[secure]
....
ERROR: Error during SonarQube Scanner execution
ERROR: You're only authorized to execute a local (preview) SonarQube analysis without pushing the results to the SonarQube server. Please contact your SonarQube administrator.
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
在我看来,travis没有将结果上传到SonarCloud的权限。是令牌或某些声纳配置中的问题。最后我找到了解决方案。在yml文件所在的根路径中,您必须添加: 声纳项目。属性
# Required metadata
sonar.projectKey=java-sonar-runner-simple:master
sonar.projectName=Rss-service
sonar.projectVersion=1.0
# Comma-separated paths to directories with sources (required)
sonar.sources=/microservice-application/rss-reader-service/src/main/java
sonar.java.binaries=/microservice-application/rss-reader-service/target/classes
# Language
sonar.language=java
# Encoding of the source files
sonar.sourceEncoding=UTF-8
在travis.yml中,我添加了:
脚本:
编辑:
sonar-project.properties不需要。只有maven目标才有意义。在SonarCloud上配置项目的正式入口点是:
- 您将看到,对于Maven项目,根本不需要创建
文件sonar project.properties
- 你甚至可以找到一个链接,链接到一个在云上分析的
sonar项目。属性,我在gradle插件中手动导入值。你好,Fabrice,一些用户在Maven执行中遇到了一个相关问题。关于这个问题的更多信息:在你的帖子上看到我的答案:你做错了什么,一切都正常。
# other script steps might be done before running the actual analysis
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar