在 Eclipse 中将项目与声纳相关联

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16191413/
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-09-10 21:40:39  来源:igfitidea点击:

Associating a Project to Sonar in Eclipse

eclipsesonarqube

提问by Anitha Kantharaju

I have Eclipse Indigo 3.7 base with MyEclipse 10 Java enterprise development plug-in:

我有带有 MyEclipse 10 Java 企业开发插件的 Eclipse Indigo 3.7 基础:

  • I have installed Sonar plug-in for eclipse.
  • Installed Sonar server and running it locally from localhost (localhost:9000)
  • Tested the Server connection in Eclipse from
    Windows>Preferences>Sonar>Servers. Connection is successful.
  • For my Project, ran the Maven goal for sonar (sonar:sonar). Build is successful. I am able to browse the results in localhost. (localhost:9000)
  • 我已经为 Eclipse 安装了 Sonar 插件。
  • 安装声纳服务器并从本地主机(本地主机:9000)本地运行它
  • 在 Eclipse 中从
    Windows>Preferences>Sonar>Servers测试服务器连接。连接成功。
  • 对于我的项目,运行声纳 (sonar:sonar) 的 Maven 目标。构建成功。我能够在本地主机中浏览结果。(本地主机:9000)

My issue is with Associating the project to Sonar. When i right click on my project, Configure > Associate with Sonar, I get a screen where nothing happens.

我的问题是将项目与声纳相关联。当我右键单击我的项目时,配置 > 与声纳关联,我得到一个没有任何反应的屏幕。

Basically the screen has 2 fields,Project and Sonar Project. The Project field contains the name of my Project and Sonar Project field lists this message - "click here to start searching for a remote Sonar project"

基本上屏幕有 2 个字段,Project 和 Sonar Project。Project 字段包含我的 Project 的名称,Sonar Project 字段列出了此消息 - “单击此处开始搜索远程 Sonar 项目”

  • I click on that field and enter my groupid:artifactid but nothing happens.
  • I also tried entering the Project Name listed in Sonar dashboard but that also does not help.
  • 我单击该字段并输入我的 groupid:artifactid 但没有任何反应。
  • 我还尝试输入 Sonar 仪表板中列出的项目名称,但这也无济于事。

When i right click on my project, In the context menu i am unable to see 'Sonar' option.

当我右键单击我的项目时,在上下文菜单中我看不到“声纳”选项。

Help me associate my project to Sonar in eclipse. Please let me know what i am missing. Thanks in advance.

帮助我将我的项目与 Eclipse 中的声纳相关联。请让我知道我缺少什么。提前致谢。

回答by Artem Khojoyan

I had the same issue with my Liferay project in Eclipse (liferay-plugins-sdk.6.2.0) and here is how I got it working:

我在 Eclipse (liferay-plugins-sdk.6.2.0) 中的 Liferay 项目遇到了同样的问题,这是我如何让它工作的:

  • Install the eclipse plugin, and test server connection
  • Install the Sonar server and start it (for example on yourhost:9000)
  • Go to yourhost:9000and login (admin/admin unless you changed it)
  • Go to Settings -> System -> Provisioning
  • Create new project (+Createin the top right corner)
  • I've used key=Liferay6.2 and name=liferay-plugins-sdk-6.2.0
  • 安装eclipse插件,并测试服务器连接
  • 安装 Sonar 服务器并启动它(例如在 上yourhost:9000
  • 转到yourhost:9000并登录(管理员/管理员,除非您更改它)
  • 转到设置 -> 系统 -> 配置
  • 创建新项目(+Create在右上角)
  • 我使用过 key=Liferay6.2 和 name=liferay-plugins-sdk-6.2.0

After the above steps I went back to my eclipse project and in Configure > Associate with SonarI was able to search/find the liferay project.

在上述步骤之后,我回到了我的 eclipse 项目,并且Configure > Associate with Sonar能够搜索/找到 liferay 项目。

回答by Fabrice - SonarSource Team

When using Sonar Eclipse, you can associate Eclipse projects only to the corresponding Sonar modules (unless you are working on a single-module project, which is pretty rare in fact).

使用 Sonar Eclipse 时,您只能将 Eclipse 项目关联到相应的 Sonar 模块(除非您正在处理单模块项目,这实际上非常罕见)。

This means that you can't associate the root project (which is logical as by definition, a root project has no sources in Sonar). You have to right-click on all the imported Maven modules, and associate them all in a single run.

这意味着您不能关联根项目(根据定义,根项目在 Sonar 中没有源是合乎逻辑的)。您必须右键单击所有导入的 Maven 模块,并在一次运行中将它们全部关联。

回答by Anuruddha Lanka Liyanarachchi

Go to your project folder in eclipse workspace from the terminal and run following command:

从终端转到 eclipse 工作区中的项目文件夹并运行以下命令:

 mvn sonar:sonar

This command will create your sonar project. Try associating the project again. Make sure you enter the name associated with your project from your pom file. (Clear the text field)

此命令将创建您的声纳项目。再次尝试关联项目。确保从 pom 文件中输入与项目关联的名称。(清除文本字段)

回答by virendra

BEST ANSWER AFTER SO MUCH ANALYSIS(I have faced the same problem)

经过这么多分析后的最佳答案(我遇到了同样的问题)

  1. Forget to add to associate with SonarQube first
  2. If you want to add sonar group id create sonar-project.properties
  1. 忘记先添加与 SonarQube 关联
  2. 如果要添加声纳组 ID 创建 sonar-project.properties

Just add below code

只需添加以下代码

# Required metadata
sonar.projectKey=javapractice
sonar.projectName=javapractice
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
  1. download sonnar-runner from github.
  2. download sonar example from github
  3. download sonar
  4. run sonar as per your operating system from command prompt
  5. go to sonar example path like c:/sonar example/java/.. /.. *.propertiespath (beside src)
  6. run sonnar-runner c:/.... / sonnar-runner.bat -e
  7. go to browser http://localhost:9000after that (login:admin/admin)
  8. your project is displayed in the browser.
  1. 从github下载sonnar-runner。
  2. 从github下载声纳示例
  3. 下载声纳
  4. 根据您的操作系统从命令提示符运行声纳
  5. 转到声纳示例路径,如c:/sonar example/java/.. /.. *.properties路径(在 src 旁边)
  6. 运行sonnar-runner c:/.... / sonnar-runner.bat -e
  7. 之后转到浏览器http://localhost:9000(登录:admin/ admin
  8. 您的项目显示在浏览器中。

回答by Kavitha Rajasekharan

Choose Mavenon the project and then choose Select Maven Profilesand then choose with-sonarin Eclipse. This will enable the Sonar functionality on projects. Now you will see the Sonaroption when you right click on projects.

在项目上选择Maven,然后选择Select Maven Profiles,然后在 Eclipse 中选择with-sonar。这将启用项目的声纳功能。现在,当您右键单击项目时,您将看到声纳选项。