我们如何在 android studio 中集成 sonarqube?我遇到过使用 sonarqube 的静态代码分析.解释我们如何实现这一目标.有许多链接可用于集成 sonar-runner 和 sonarqube,但要么已过时,要么不足以完成工作.
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 是服务器端的静态代码分析工具.编写干净和高质量的代码非常有用.您应该在 localhost 或服务器上运行 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-
现在在 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-
File -> Settings -> Plugins -> 然后输入 sonarqube 并点击在底部的浏览存储库.
File -> Settings -> Plugins -> then type sonarqube and click on Browse repositories at the bottom.
打开 build.gradle 文件,添加插件 sonarqube.org 并添加以下属性-
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 端,您的设置已完成,运行命令 -gradle sonarqube 运行分析.
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 中集成 sonarqube?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!