Java 声纳:您必须为未解析的未知定义以下强制性属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26092773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 01:49:47  来源:igfitidea点击:

Sonar: You must define the following mandatory properties for unknown not resolved

javasonarqubesonar-runner

提问by baconSoda

I'm trying to run SonarQube on a project in java. I configured the sonar properties file and placed it in the project directory. On running the sonar.bat there is an error that asks to define the mandatory parameters. At first I assumed my properties file was wrong, but I've tried everything I can think of.

我正在尝试在 Java 项目上运行 SonarQube。我配置了声纳属性文件并将其放在项目目录中。运行 sonar.bat 时出现错误,要求定义强制参数。起初我认为我的属性文件是错误的,但我已经尝试了所有我能想到的方法。

this is the current properties file

这是当前的属性文件

# Required metadata
sonar.projectKey=_newtest2
sonar.projectName=NoSqlDataModeling
sonar.projectVersion=2.0

# Path to the parent source code directory.
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set. 
# If not set, SonarQube starts looking for source code from the directory containing 
# the sonar-project.properties file.
sonar.sources=D:/eclipse workspace/NoSqlDataModeling


#Comma-separated paths to directories containing the binary files (directories with class files, in the case of Java).
sonar.binaries=D:/eclipse workspace/NoSqlDataModeling/build/classes

#Comma-separated paths to files with third-party libraries (JAR files in the case of Java). Patterns #can be used.
sonar.libraries=D:/eclipse workspace/NoSqlDataModeling/WebContent/WEB-INF/lib/*.jar

#language used
sonar.language=java

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

# Additional parameters
sonar.my.property=value

this is the error message

这是错误信息

INFO: SonarQube Server 4.3.1
09:58:57.783 INFO  - Load batch settings
09:58:57.901 INFO  - User cache: C:\Users\Rohan.Kumar\.sonar\cache
09:58:57.907 INFO  - Install plugins
09:58:57.913 INFO  - Download sonar-maven-batch-plugin-4.3.1.jar
09:58:58.037 INFO  - Download sonar-findbugs-plugin-2.1.jar
09:58:58.436 INFO  - Download sonar-surefire-plugin-2.1.jar
09:58:58.540 INFO  - Download sonar-cpd-plugin-4.3.1.jar
09:58:58.870 INFO  - Download sonar-core-plugin-4.3.1.jar
09:58:58.956 INFO  - Download sonar-java-plugin-2.1.jar
09:58:59.097 INFO  - Download sonar-dbcleaner-plugin-4.3.1.jar
09:58:59.216 INFO  - Download sonar-jacoco-plugin-2.1.jar
09:58:59.331 INFO  - Download sonar-l10n-en-plugin-4.3.1.jar
09:58:59.350 INFO  - Download sonar-squid-java-plugin-2.1.jar
09:58:59.453 INFO  - Download sonar-email-notifications-plugin-4.3.1.jar
09:58:59.655 INFO  - Download sonar-design-plugin-4.3.1.jar
09:58:59.826 INFO  - Install JDBC driver
09:59:00.061 WARN  - H2 database should be used for evaluation purpose only
09:59:00.061 INFO  - Create JDBC datasource for jdbc:h2:tcp://localhost/sonar
09:59:00.784 INFO  - Initializing Hibernate
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 7.521s
Final Memory: 5M/19M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: You must define the following mandatory properties for 'Unknow
n': sonar.projectKey, sonar.projectName, sonar.projectVersion, sonar.sources
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with t
he -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.

Should I provide comma separated paths to all the class files and java files? Till what depth do I provide the paths? the different class files are located in build/classes/.../.../<4 different folders that have class files inside them> I change the project key every time as I read it has to be unique.

我应该为所有类文件和 java 文件提供逗号分隔的路径吗?我提供路径到什么深度?不同的类文件位于 build/classes/.../.../<4 个不同的文件夹,其中包含类文件> 我每次阅读时更改项目密钥必须是唯一的。

回答by Gene

How to Upload a Project to SonarQube:

如何将项目上传到 SonarQube:

1) Startup SonarQube. You should be able to see it if you type localhost:9000 into your browser.

1) 启动 SonarQube。如果您在浏览器中键入 localhost:9000,您应该能够看到它。

2) In command prompt, cd to the directory of your project enter image description here

2)在命令提示符下, cd 到您的项目目录 在此处输入图片说明

3) Make sure the root folder of your project has “sonar-project.properties” file and that it is configured. If your project doesn't have the “sonar-project.properties” file, it will get this error= Sonar Setup Undefined Mandatory Properties

3) 确保你的项目的根文件夹有“sonar-project.properties”文件并且已经配置好了。如果你的项目没有“sonar-project.properties”文件,它会得到这个错误= Sonar Setup Undefined Mandatory Properties

My “sonar-project.properties” file for my VendingMachineEmulator app looks like this: enter image description here

我的 VendingMachineEmulator 应用程序的“sonar-project.properties”文件如下所示: 在此处输入图片说明

4) In command prompt, now type “C:\sonar-scanner\sonar-scanner-2.6.1\bin\sonar-scanner.bat”. Alternatively, you could've also type “C:\sonar-scanner\sonar-scanner-2.6.1\bin\sonar-runner.bat” too. I'm not sure what the difference is. Make sure the directory you are in is still the main folder of your project.

4) 在命令提示符下,现在输入“C:\sonar-scanner\sonar-scanner-2.6.1\bin\sonar-scanner.bat”。或者,您也可以输入“C:\sonar-scanner\sonar-scanner-2.6.1\bin\sonar-runner.bat”。我不确定有什么区别。确保您所在的目录仍然是项目的主文件夹。

5) Done! Refresh localhost:9000 and check if the project is there.

5)完成!刷新 localhost:9000 并检查项目是否存在。

回答by AdityaJ

Try running sonar-scanner command from the directory where sonar-project.properties lies.

尝试从 sonar-project.properties 所在的目录运行 sonar-scanner 命令。

I faced same problem and later found I was running the command from the different directory.

我遇到了同样的问题,后来发现我正在从不同的目录运行命令。

回答by P Satish Patro

Those who are getting "EXECUTION FAILURE" on running sonar-runner in project folder add -Dproject.settings=./sonar-project.properties

那些在项目文件夹中运行 sonar-runner 时遇到“执行失败”的人添加 -Dproject.settings=./sonar-project.properties

As it can't able to find setting file, you have to mention it explicitly

由于它无法找到设置文件,您必须明确提及它

sonar-project.properties is the file name in my project where I have gave projectKey, projectName

sonar-project.properties 是我的项目中的文件名,我在其中提供了 projectKey、projectName

For me, D:\TB-2 24 sept\server side\ServerSide>C:\Users\m1042220\Downloads\sonar-plugin\agent\sonar-plugin-agent\sonar-qube-runner\bin\sonar-runner -Dproject.settings=./sonar-project.properties

为了我, D:\TB-2 24 sept\server side\ServerSide>C:\Users\m1042220\Downloads\sonar-plugin\agent\sonar-plugin-agent\sonar-qube-runner\bin\sonar-runner -Dproject.settings=./sonar-project.properties