【问题标题】:Sonar Setup Undefined Mandatory Properties声纳设置未定义的强制属性
【发布时间】:2014-02-07 20:56:33
【问题描述】:

正在学习如何使用 SonarQube 并正在通过 here 进行快速安装

一直到第 5 步。执行时我的构建失败: C:\sonar-runner\bin\sonar-runner.bat

我收到以下错误:

INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 7.572s
Final Memory: 8M/223M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: You must define the following mandatory properties for 'Unknown':   sonar.projectKey, sonar.projectName, sonar.projectVersion, sonar.sources
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.

有人遇到过类似的情况并解决了吗?

【问题讨论】:

  • 项目是什么语言? (Java、.net 等)
  • 这是一个java项目。

标签: batch-file sonarqube


【解决方案1】:

如果你有一个 java 项目,你必须在你执行 sonar runner 的文件夹中创建一个 sonar-project.properties 文件。您必须在此文件中定义以下属性:

# Required metadata
sonar.projectKey=java-sonar-runner-simple
sonar.projectName=Simple Java project analyzed with the SonarQube Runner
sonar.projectVersion=1.0

# Comma-separated paths to directories with sources (required)
sonar.sources=src

# Language
sonar.language=java

# Encoding of the source files
sonar.sourceEncoding=UTF-8

希望这会有所帮助,

【讨论】:

  • 谢谢。仅供参考:我将 Jenkins 2.10 与 Sonar Scanner 2.6.1 一起使用:值 src 中的路径相对于 Jenkins 作业工作区;在作业配置中,项目属性的路径是文件的相对路径(不是文件夹)。
  • 此需求不适用于 Maven 或 Gradle 项目
【解决方案2】:

对我来说,这是因为:https://stackoverflow.com/a/18779516/1068411

简而言之:您应该将声纳放入“构建后操作”,而不是“构建后步骤”。

【讨论】:

【解决方案3】:

对于那些在 CLI 上有类似响应并猜测您已正确设置所有内容的人,我的问题是从项目目录之外运行 sonar-runner 命令。确保你的项目中有cd,然后运行命令。

【讨论】:

    【解决方案4】:

    在 Jenkins 内部,以下声纳属性对我有用。

    sonar.projectKey=MyWebApp
    sonar.projectBaseDir=./MyWebApp
    sonar.projectName=MyWebApp
    sonar.projectVersion=1.0
    sonar.sources=./src/main/java
    sonar.language=java
    sonar.java.binaries=.
    ##to avoid this exception Caused by: org.tmatesoft.svn.core.SVNAuthenticationException: svn: E170001
    sonar.scm.disabled=True
    sonar.sourceEncoding=UTF-8
    

    希望它对某人有所帮助。
    谢谢!

    【讨论】:

      猜你喜欢
      • 2014-11-23
      • 2014-02-06
      • 2023-01-02
      • 2019-08-09
      • 2013-05-20
      • 2021-11-27
      • 2017-09-02
      • 2022-10-30
      相关资源
      最近更新 更多