gradle集成sonarqube

先在项目的 build.gradle中配置sonar插件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        maven{ url'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven{ url'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
        maven {url "https://plugins.gradle.org/m2/"}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6"
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

// plugins段放置位置有要示,放在buildscript段前面会报错,放到文件最末尾也报错,紧跟buildscript放置OK,其余位置没有偿试
plugins {
    // 添加插件信息
    id "org.sonarqube" version "2.6"
}
// 声明插件
apply plugin: "org.sonarqube"

// 如果项目不存在嵌套的子项目,则以上配置即可
// 如果项目存在嵌套的子项目,还要添加以下配置
sonarqube {
    properties {
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.verbose", "true"
        property "sonar.sources", "src/main/java"
    }
}

allprojects {
    repositories {
        google()
        maven{ url'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven{ url'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

 

然后在gradle.properties中配置sonar的配置信息

#sonar配置
systemProp.sonar.host.url=http://10.7.*.*/sonar
systemProp.sonar.login=用户名或者令牌
systemProp.sonar.projectKey=abcd123
systemProp.sonar.projectName=项目名称

最后执行gradle sonarqube或者gradlew sonarqube,出现BUILD SUCCESSFUL,则执行成功

The following classes needed for analysis were missing:
  java.rmi.Remote

BUILD SUCCESSFUL in 2m 15s
22 actionable tasks: 11 executed, 11 up-to-date

登录http://10.7.*.*/sonar,找到对应的项目,就可以查看结果了!

 

gradle集成sonarqube_第1张图片

你可能感兴趣的:(android,gradle,sonarqube)