How to setup and configure Sonar for Groovy projects

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

  1. If your project is not mavenised, you will need to create a pom.xml.
    cd into your project folder and run:

    <style type="text/css"> <!-- .bwp-syntax-wrapper li {white-space:normal} --> </style>
    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
  2. Edit your pom xml. Add:
    <style type="text/css"> <!-- .bwp-syntax-wrapper li {white-space:normal} --> </style>
     <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

  1. You need to install the Flex plugin to enable analysis of AS3 and flex projects:
    Go to System>Update Center:
    Screen shot 2011 06 24 at 14.36.38 How to setup and configure Sonar for Groovy projects
  2. Under Available plugins find Groovy and click install:
    Screen shot 2011 06 27 at 16.01.05 How to setup and configure Sonar for Groovy projects
  3. Restart sonar:
    <style type="text/css"> <!-- .bwp-syntax-wrapper li {white-space:normal} --> </style>
    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...
  4. Go to the sonar profiles page.
    If you installed sonar locally, the default url is:

    <style type="text/css"> <!-- .bwp-syntax-wrapper li {white-space:normal} --> </style>
    http://localhost:9000/profiles/projects/
    http://localhost:9000/profiles/projects/

    If the installation was successful, you should see a ‘Sonar Groovy Way ‘ section:
    Screen shot 2011 06 28 at 13.11.51 How to setup and configure Sonar for Groovy projects

3. How to gather data from your Groovy project and analyse it in Sonar

  1. cd into your project folder. Clean and Install your project into your local maven repo:
    <style type="text/css"> <!-- .bwp-syntax-wrapper li {white-space:normal} --> </style>
    mvn clean install
    mvn clean install
  2. run the sonar analysis:
    <style type="text/css"> <!-- .bwp-syntax-wrapper li {white-space:normal} --> </style>
    mvn sonar:sonar
    mvn sonar:sonar
  3. Go to your Sonar profile page. For local installs the default url is: http://localhost:9000/profiles
  4. Click on +Create or ‘Sonar Groovy Way‘ and add your project to the associated projects:groovyprofile How to setup and configure Sonar for Groovy projects
  5. 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

  1. Go to Help>Install New software
    Enter the Sonar Update Site:

    <style type="text/css"> <!-- .bwp-syntax-wrapper li {white-space:normal} --> </style>
    http://dist.sonar-ide.codehaus.org/eclipse/
    http://dist.sonar-ide.codehaus.org/eclipse/

    Screen shot 2011 06 27 at 17.39.37 How to setup and configure Sonar for Groovy projects

  2. Click Next, Accept T&C, Reboot STS when prompted
  3. go to preferences, type in sonar to the filter:
    Screen shot 2011 06 27 at 11.49.36 How to setup and configure Sonar for Groovy projectsIf 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.
  4. 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
  5. Right click on your project in the Project explorer, go to Configure > Associate with Sonar:
    Screen shot 2011 06 27 at 17.54.42 How to setup and configure Sonar for Groovy projects
  6. 1. Select your Sonar server from the dropdown list
    2. Copy the GroupID and ArtifactID from your pom.xml
    3. Click on Find on ServerScreen shot 2011 06 27 at 18.01.32 How to setup and configure Sonar for Groovy projects
  7. Switch over to Sonar View:
    Screen shot 2011 06 28 at 13.22.43 How to setup and configure Sonar for Groovy projectsScreen shot 2011 06 28 at 13.24.04 How to setup and configure Sonar for Groovy projects
  8. If the sonar analysis was successful, your Measures, Web, Hotspots and Violations panel will be populated with the gathered data.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值