无法在项目 jraft 上执行目标 org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar (default-cli):没有治理许可

Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar (default-cli) on project jraft: No license for governance

我正尝试在 travis 上为 Maven 项目设置 SonarQube.com,但我在构建时看到以下异常:

[INFO] User cache: /home/travis/.sonar/cache
[INFO] Load global settings
[INFO] Load global settings (done) | time=456ms
[INFO] User cache: /home/travis/.sonar/cache
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=16ms
[INFO] Download sonar-scm-cvs-plugin-1.0.jar
[INFO] Download sonar-scm-svn-plugin-1.3.jar
[INFO] Download sonar-plsql-plugin-2.9.0.901.jar
[INFO] Download sonar-csharp-plugin-5.8.0.660.jar
[INFO] Download sonar-java-plugin-4.7.1.9272.jar
[INFO] Download sonar-web-plugin-2.5.0.476.jar
[INFO] Download sonar-flex-plugin-2.3.jar
[INFO] Download sonar-xml-plugin-1.4.2.885.jar
[INFO] Download sonar-vbnet-plugin-3.0.3.346.jar
[INFO] Download sonar-swift-plugin-2.0.0.1127.jar
[INFO] Download sonar-python-plugin-1.7.0.1195.jar
[INFO] Download sonar-github-plugin-1.4.0.699.jar
[INFO] Download sonar-cfamily-plugin-4.6.0.7071.jar
[INFO] Download sonar-auth-github-plugin-1.3.jar
[INFO] Download sonar-rpg-plugin-2.1.0.736.jar
[INFO] Download sonar-scm-mercurial-plugin-1.1.1.jar
[INFO] Download sonar-googleanalytics-plugin-1.1.jar
[INFO] Download sonar-widget-lab-plugin-1.8.1.jar
[INFO] Download sonar-pli-plugin-1.5.0.702.jar
[INFO] Download sonar-javascript-plugin-2.21.0.4409.jar
[INFO] Download sonar-groovy-plugin-1.4.jar
[INFO] Download sonar-cobol-plugin-3.3.1.1636.jar
[INFO] Download sonar-scm-git-plugin-1.2.jar
[INFO] Download sonar-php-plugin-2.10.0.2087.jar
[INFO] Download sonar-abap-plugin-3.3.jar
[INFO] Download sonar-governance-plugin-2.0.0.1789.jar
[INFO] Download qualinsight-sonarqube-badges-3.0.1.jar
[INFO] SonarQube version: 6.3.0
[INFO] Default locale: "en_US", source code encoding: "UTF-8"
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:42 min
[INFO] Finished at: 2017-04-03T09:47:20+00:00
[INFO] Final Memory: 70M/468M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar (default-cli) on project jraft: No license for governance -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

这里是 .travis.yml:

language: java
jdk:
  - oraclejdk8

addons:
  sonarqube:
    organization: ${SONAR_ORGANIZATION}
    token:
      secure: ${SONAR_TOKEN}

script:
  - ./travis.sh

cache:
  directories:
    - $HOME/.m2/repository
    - $HOME/.sonar
    - $HOME/jvm
    - $HOME/maven

这里是 travis.sh:

#!/bin/bash

set -e

INITIAL_VERSION=1.0-SNAPSHOT

export MAVEN_OPTS="-Xmx1G -Xms128m"

mvn package sonar:sonar \
  $MAVEN_ARGS \
  -Dsonar.host.url=$SONAR_HOST_URL \
  -Dsonar.login=$SONAR_TOKEN \
  -Dsonar.projectVersion=$INITIAL_VERSION

为什么我看到这个错误 No license for governance 因为我没有使用任何商业声纳组件(我想只有声纳-java)?

问题似乎与其中一个插件需要商业密钥这一事实有关,但我如何告诉 Travis 只安装 java 插件?

sonar-governance 插件是商业插件。 检查 here

.....
[INFO] Download sonar-governance-plugin-2.0.0.1789.jar
......

查看您的存储库,您不应覆盖 Travis 附加组件为您指定的各种参数。

更具体地说,当您在 Maven 命令行上覆盖 SONAR_TOKEN(在 line 12), the consequence is that the token that you have encrypted and passed at line 11.travis.yml 文件被完全清除。因此,您的分析是 运行 就像你是匿名的。

所以请遵循 Get Started 指南并简单地 运行 以下 Maven 命令:

mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar

对我来说,下面的作品来自我的詹金斯管道

node{
   stage 'Code Quality'
   sh "mvn sonar:sonar -Dsonar.host.url=http://<hostname>:9000"
}