Sonar is an open platform to manage code quality. Sonar can gather data from your Groovy projects and display them on a web interface or straight in SpringSource Toolkit via an eclipse plugin.
1. How to enable analysis of your Groovy projects
- If your project is not mavenised,you will need to create a pom.xml.
cd into your project folder and run:
mvn org.grails:grails-maven-plugin:1.3.7:create-pom -DgroupId=YOURGROUPID
mvn org.grails:grails-maven-plugin:1.3.7:create-pom -DgroupId=YOURGROUPID
- Edit your pom xml. Add:
<sourceDirectory>src/main/groovy</sourceDirectory>
<properties>
<sonar.language>grvy</sonar.language>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
</properties>
<sourceDirectory>src/main/groovy</sourceDirectory>
<properties>
<sonar.language>grvy</sonar.language>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
</properties>
2. How to add your project to the sonar console
- You need to install the Flex plugin to enable analysis of AS3 and flex projects:
Go to System>Update Center:
![](http://img50.lidatong.com.cn//uploads/allimg/c20201214/0150c6e24500e03a9fb85f244732cbac.gif)
- Under Available plugins find Groovy and click install:
![](http://img50.lidatong.com.cn//uploads/allimg/c20201214/71e7f9b78cd88ff7f02bcf97a0b1f5c7.gif)
- Restart sonar:
macosx-universal-64/sonar.sh stop
macosx-universal-64/sonar.sh console
..or the linux/windows equivalent...
macosx-universal-64/sonar.sh stop
macosx-universal-64/sonar.sh console
..or the linux/windows equivalent...
- Go to the sonar profiles page.
If you installed sonar locally,the default url is:
http://localhost:9000/profiles/projects/
http://localhost:9000/profiles/projects/
If the installation was successful,you should see a ‘Sonar Groovy Way ‘ section:
![](http://img50.lidatong.com.cn//uploads/allimg/c20201214/501276ddece6ec214900895410175de5.gif)
3. How to gather data from your Groovy project and analyse it in Sonar
- cd into your project folder. Clean and Install your project into your local maven repo:
- run the sonar analysis:
- Go to your Sonar profile page. For local installs the default url is: http://localhost:9000/profiles
- Click on +Create or ‘Sonar Groovy Way‘ and? add your project to the associated projects:
![](http://img50.lidatong.com.cn//uploads/allimg/c20201214/dbb98a62a5d0020b160de32869528c32.gif)
- Go back to your sonar web interface (http://localhost:9000) –? the reports on all gathered data should be displayed.
4. How to install and configure the Sonar Eclipse Plugin in STS
- Go to Help>Install New software
Enter the Sonar Update Site:
http://dist.sonar-ide.codehaus.org/eclipse/
http://dist.sonar-ide.codehaus.org/eclipse/
![](http://img50.lidatong.com.cn//uploads/allimg/c20201214/e71feaff64824e7927b2cb88b248644b.gif)
- Click Next,Accept T&C,Reboot STS when prompted
- go to preferences,type in sonar to the filter:
![](http://img50.lidatong.com.cn//uploads/allimg/c20201214/e569d1e30a3214a335192efc21717644.gif) If you are running sonar on http://localhost:9000/,then you don’t need to do anything. If your are running on a different host:port,click on add and and add a new Sonar Server URL.
- To verify the connection you can click on edit and click on Test Connection. In the console you should get:
[INFO] Connected to Sonar 2.8
[INFO] Connected to Sonar 2.8
- Right click on your project in the Project explorer,go to Configure > Associate with Sonar:
![](http://img50.lidatong.com.cn//uploads/allimg/c20201214/65be58080301e7bcca61b400633a082a.gif)
- 1. Select your Sonar server from the dropdown list
2. Copy the GroupID and ArtifactID from your pom.xml 3. Click on Find on Server![](http://img50.lidatong.com.cn//uploads/allimg/c20201214/8f447dbfe2c65b1d2a950176b95b568d.gif)
- Switch over to Sonar View:
![](http://img50.lidatong.com.cn//uploads/allimg/c20201214/a6a8dc5799659a414ec86c8c98908dd3.gif)
![](http://img50.lidatong.com.cn//uploads/allimg/c20201214/9de3022cbbab6b3970a807debe44fb77.gif)
- If the sonar analysis was successful,your Measures,Web,Hotspots and Violations panel will be populated with the gathered data.
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|