Skip to content

Latest commit

 

History

History
158 lines (119 loc) · 5.07 KB

README-zh.md

File metadata and controls

158 lines (119 loc) · 5.07 KB

OkCheck

Download

差量扫描,自动集成Lint、KtLint、UnitTest、Checkstyle、Findbugs、Pmd 强大且灵活的Android Gradle插件

English

基本差量扫描

  • 基于Git仓库,对比最近一次扫描成功的记录commit id => 扫描差量的module
  • 基于本地代码, 对比最近一次扫描成功的缓存 => 已经处理的任务直接up-to-data

案例

如何引入

在根项目的build.gradle中配置:

buildscript {
    dependencies {
        classpath 'com.liulishuo.okcheck:gradle:0.2.8'
    }
}

allprojects {
    apply plugin: 'okcheck'
}

至此,就已经完全整合,并且采用我们定制的统一规则生效5大静态扫描工具与单元测试,以及可以通过./gradlew okcheck差分静态扫描,并且默认所有报告会整合到根项目的build/reports目录下,方便统一导出(但是如果你想要报告存在原本的目录,只需要将destination设置为project.buildDir即可)。

如果你希望使用Snapshot版本,请添加以下仓库到你的gradle.build:

buildscript {
  repositories {
      maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
  }
}

任务说明

当进行okcheck任务的时候,会对所有的variant进行编译与扫描(如有一般都有debugrelease两个编译类型导致,存在至少两个variant),因此通常来说我们只需要对某一个variant进行编译扫描即可: 如okcheckDebug

  • ./gradlew okcheckDebug: 执行差量的扫描
  • ./gradlew cleanOkcheckDiff: 清除所有缓存的差量数据,下次会全量扫描
  • ./gradlew -PignoreOkcheckDiff okcheck: 忽略差量数据进行全量的扫描
  • ./gradlew -PignoreOkCheckDiff :module1:okcheck: 忽略差量数据进行module1模块的扫描

如何配置

为了方便说明下面所有提到的,都采用默认值(当没有提供时所采用的默认值)作为案例,以下是在根项目的build.gradle中配置:

allprojects {
    apply plugin: 'okcheck'

    okcheck {
        exclude = ['**/proto/*.java']
        destination = project.rootProject.buildDir

        unittest {
            enabled = true
        }
        lint {
            enabled = true
            exclude = ['**/proto/*.java']

        }
        ktlint {
            enabled = true
            exclude = ['**/proto/*.java']
            version = "0.22.0"
        }
        checkstyle {
            enabled = true
            exclude = ['**/proto/*.java']
            // 采用默认的统一配置
            configFile = null
        }
        findbugs {
            enabled = true
            exclude = ['**/proto/*.java']

            effort = "default"

            // Warning级别的错误默认会终止扫描
            ignoreFailures = false
            // 采用默认的统一配置
            excludeFilter = null
        }
        pmd {
            enabled = true
            exclude = ['**/proto/*.java']

            // Warning级别的错误默认会终止扫描
            ignoreFailures = false
            // 采用默认的统一配置
            ruleSetFiles = null
        }

        coverageReport {
            xml.enabled = false
            html.enabled = false
            csv.enabled = false
        }
    }
}

其他

  • 首次执行okcheck任务会进行全量扫描
  • 如果你希望针对checkstyle任务suppress一些方法与行,对于默认内置的checkstyle的配置,有只需要在根项目目录添加suppressions.xml文件,并在里面定义它们即可

已经忽略包

checkstyle,findbugs,pmd中忽略了以下路径的扫描:

**/gen/**
**/test/**
**/proto/*.java
**/protobuf/*.java
**/com/google/**/*.java

LICENSE

Copyright (c) 2018 LingoChamp Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.