Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Associating a Project to Sonar in Eclipse

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

  • 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)

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"

  • 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.

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.

like image 565
Anitha Kantharaju Avatar asked Apr 24 '13 11:04

Anitha Kantharaju


4 Answers

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

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/.. /.. *.properties path (beside src)
  6. run sonnar-runner c:/.... / sonnar-runner.bat -e
  7. go to browser http://localhost:9000 after that (login:admin/admin)
  8. your project is displayed in the browser.
like image 167
virendra Avatar answered Nov 10 '22 13:11

virendra


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

 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)

like image 30
Anuruddha Lanka Liyanarachchi Avatar answered Nov 10 '22 14:11

Anuruddha Lanka Liyanarachchi


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:

  • Install the eclipse plugin, and test server connection
  • Install the Sonar server and start it (for example on yourhost:9000)
  • Go to yourhost:9000 and login (admin/admin unless you changed it)
  • Go to Settings -> System -> Provisioning
  • Create new project (+Create in the top right corner)
  • I've used key=Liferay6.2 and name=liferay-plugins-sdk-6.2.0

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

like image 10
Artem Khojoyan Avatar answered Nov 10 '22 14:11

Artem Khojoyan


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).

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.

like image 4
Fabrice - SonarSource Team Avatar answered Nov 10 '22 14:11

Fabrice - SonarSource Team