如何在Android Studio中集成声纳? [英] How to integrate sonarqube in android studio?

查看:88
本文介绍了如何在Android Studio中集成声纳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何将声纳法集成到android studio中?我遇到了使用声纳法的静态代码分析.解释我们如何实现这一目标.有许多链接可用于集成声纳运行器和声纳,但它们过时或不足以完成工作.

How we can integrate sonarqube in android studio? I have come across static code analysis using sonarqube. Explain how we can achieve that. There are many link available to integrate sonar-runner and sonarqube but either outdated or not sufficient to get the job done.

推荐答案

Sonarqube是服务器端的静态代码分析器工具.编写干净且高质量的代码非常有用. 您应该在本地主机或服务器上运行sonarqube.在那里创建一个新项目,该项目提供名称和唯一ID,我们将使用该名称和唯一身份将我们与用户名和密码一起标识给服务器.不需要在服务器端进行一些设置,例如-

Sonarqube is static code analyzer tool on server side. It is very useful to write clean and quality code. You should have sonarqube running on localhost or server. There create a new project giving name and unique id, this name and unique we will use to identify us to the server along with our username and password. Few things need to be set up on server side like-

  1. 创建用户.
  2. 创建具有唯一ID的新项目.

现在,在Android Studio中,我们将使用 gradle sonarqube 命令与sonarqube一起分析我们的项目.

Now in Android studio we are going use gradle sonarqube command to analyze our project with sonarqube.

运行gradle sonarqube命令之前,需要完成以下步骤-

There are following steps need to be covered before running gradle sonarqube command-

  1. 首先,我们需要在计算机上安装gradle.
  2. (可选)在Android Studio中安装sonarqube插件.转到-

文件->设置->插件->然后键入sonarqube并单击 在底部的浏览存储库中.

File -> Settings -> Plugins -> then type sonarqube and click on Browse repositories at the bottom.

  1. 打开build.gradle文件,添加插件sonarqube.org并添加 以下属性-

  1. Open build.gradle file, add plugin sonarqube.org and add following properties-

apply plugin: "org.sonarqube"

sonarqube {
    properties {
        property "sonar.projectName", "MyProject"
        property "sonar.projectKey", "com.example.myproject"
        property "sonar.host.url", "http://192.114.1.1:9000"
        property "sonar.language", "java"
        property "sonar.sources", "src/main/"
        property "sonar.login", "username"
        property "sonar.password", "password"
    }
}    

  • 打开项目gradle文件,并在依赖项中添加-

  • Open project gradle file and in dependencies add-

    dependencies {
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.1"
    }
    

  • 然后在存储库中添加-

  • And in repository add-

    allprojects {
        repositories {
            maven {
                url "https://plugins.gradle.org/m2/"
            }
        }
    }
    

  • 现在在Android Studio上,您的设置已完成,请运行命令- 分级声纳以运行分析.

    Now on Android studio side your setup is done, run the command- gradle sonarqube to run the analysis.

    如果在团队中工作并且想要为所有开发人员创建不同的分支,请运行命令- gradle sonarqube -Dsonar.branch = {YouName}

    If working in team and want to create different branches for all developers, run command- gradle sonarqube -Dsonar.branch={YouName}

    这篇关于如何在Android Studio中集成声纳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆