我正在做一个项目,用 sonarqube 在 jenkins 中分析代码。 workspace下的工程结构为:/var/lib/jenkins/workspace/myproject-trunk-sonar/myproject/pom.xml,Module1,Module2等
我的 Sonar 项目.properties:
# Required metadata
sonar.projectKey=Myproject
sonar.projectName=Myproject
sonar.projectVersion=1.0
#Set modules IDs
sonar.modules=Module1, Module2
# Comma-separated paths to directories with sources (required)
sonar.sources=src/main/java
# Language
sonar.language=java
# Encoding of the source files
sonar.sourceEncoding=UTF-8
如果我的 pom.xml 和模块所在的/var/lib/jenkins/workspace/myproject-trunk-sonar/myproject 下有 sonar-project.properties 文件,我会看到以下错误:
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.
ERROR: SonarQube scanner exited with non-zero code: 1
如果我在/var/lib/jenkins/workspace/myproject-trunk-sonar 下有 sonar-project.properties 文件,我会看到以下错误:
ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: The base directory of the module 'Module1' does not exist: /var/lib/jenkins/workspace/myproject-trunk-sonar/Module1
at org.sonarsource.scanner.cli.Conf.setModuleBaseDir(Conf.java:180)
at org.sonarsource.scanner.cli.Conf.loadModuleConfigFile(Conf.java:172)
at org.sonarsource.scanner.cli.Conf.loadModulesProperties(Conf.java:137)
at org.sonarsource.scanner.cli.Conf.loadProjectProperties(Conf.java:111)
at org.sonarsource.scanner.cli.Conf.properties(Conf.java:59)
at org.sonarsource.scanner.cli.Main.execute(Main.java:68)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
ERROR: SonarQube scanner exited with non-zero code: 1
如何让 Sonar 扫描仪查看带有java代码的模块所在的目录?当我在模块所在的目录中拥有属性文件时,它甚至找不到属性文件并提示缺少必填字段。
感谢您的帮助。
最佳答案
感谢大家的回复。我能够通过修改项目的目录结构来解决问题。我删除了目录“myproject”并将 sonar-project.properties 文件放在所有模块所在的位置,并且能够成功运行扫描仪。
感谢您的帮助。
关于java - 在 Jenkins 分析时 Sonar 工作失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43264898/