我尝试按照Travis文档SonarQube
尝试在Travis上为Java项目设置https://docs.travis-ci.com/user/sonarqube/我生成的.travis.yml
文件如下:
sudo: required
cache:
directories:
- $HOME/.m2
language: java
services:
- docker
jdk:
- oraclejdk8
os:
- linux
env:
matrix:
- NEO_VERSION=3.0.9
WITH_DOCKER=true
EXTRA_PROFILES=-Pwith-neo4j-io
- NEO_VERSION=3.1.2
WITH_DOCKER=true
EXTRA_PROFILES=-Pwith-neo4j-io
addons:
sonarqube:
organization: ${SONAR_ORGANIZATION}
token:
secure: ${SONAR_TOKEN}
branches:
- master
- sonarqube
before_script:
script:
- build/run.sh
- sonar-scanner
install: true
after_success:
- mvn clean test jacoco:report coveralls:report
- "[ ${TRAVIS_PULL_REQUEST} = 'false' ] && [[ ${TRAVIS_BRANCH} = 'master' ]] && mvn clean deploy -DskipTests --settings ./deploy-settings.xml"
我生成的sonar-scanner.properties
文件是:
# must be unique in a given SonarQube instance
sonar.projectKey=liquigraph
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=Liquigraph
sonar.projectVersion=1.0
# Set modules IDs
sonar.modules=liquigraph-cli,liquigraph-core,liquigraph-maven-plugin,liquigraph-spring-boot-starter,liquigraph-examples
# Modules inherit properties set at parent level
sonar.sources=src
sonar.sourceEncoding=UTF-8
sonar.language=java
但是当我提交并且Travis开始构建时,声纳作业失败并显示以下日志:
. . .
$ sonar-scanner
INFO: Scanner configuration file: /home/travis/.sonarscanner/sonar-scanner-2.8/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 2.8
INFO: Java 1.8.0_111 Oracle Corporation (64-bit)
INFO: Linux 4.4.0-51-generic amd64
INFO: User cache: /home/travis/.sonar/cache
. . .
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 13.770s
INFO: Final Memory: 64M/505M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.sources
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
我确实将sonar-scanner.properties
放在项目文件夹的根目录中。为什么travis无法找到而是使用/home/travis/.sonarscanner/sonar-scanner-2.8/conf/sonar-scanner.properties
?
答案 0 :(得分:1)
如果您的项目是Maven项目,那么只需使用Scanner for Maven:mvn sonar:sonar
查看https://about.sonarqube.com/get-started/了解详情。
如果您确实想使用SonarQube扫描仪,那么您的问题是您没有使用配置文件的正确名称。它应该是sonar-project.properties
。