Skip to content

Static code analysis plugin for next-generation Android projects.

License

Notifications You must be signed in to change notification settings

stoyicker/android-check-2

 
 

Repository files navigation

Android Check 2

Static code analysis plugin for Android projects. This is a fork of the original android-check plugin, which implements a really useful concept, but unfortunately seems abandoned. Works for application, library and feature modules.

Current version tested with Android plugin for Gradle 3.1.3.

Who uses this?

Schibsted Products & Technology China Euro Vehicle Technology

Build status

master master

dev dev

Usage

Download

This plugin is available in the Gradle Plugin Portal. It attaches itself to the check task, but you can also execute the corresponding tasks manually when desired: androidCheckstyle for CheckStyle, and androidPmd for PMD.

In order to add it to your project, you can use this snippet for Gradle 2.1 and later:

Kotlin
plugins {
  id("org.stoyicker.android-check") version "+"
}
Groovy
plugins {
  id "org.stoyicker.android-check" version "+"
}

Or this one for older Gradle versions or where dynamic configuration is required:

Kotlin
buildscript {
    repositories {
        gradlePluginPortal()
    }
    dependencies {
      classpath("org.stoyicker.android-check:plugin:+")
    }
}

apply(plugin = "org.stoyicker.android-check")
Groovy
buildscript {
    repositories {
        gradlePluginPortal()
    }
    dependencies {
      classpath("org.stoyicker.android-check:plugin:+") {
        // These are to avoid some conflicts with the Android plugin due to how classloading is performed by Gradle
        // Only required before Gradle 4.8: https://github.com/gradle/gradle/issues/5092
        exclude module: "asm"
        exclude module: "gson"
        exclude module: "guava"
        exclude module: "commons-logging"
        // This one is required because Checkstyle and PMD use different Saxon artifacts that have overlapping packages
        // Also only required before Gradle < 4.8
        exclude module: "Saxon-HE"
      }
    }
}

apply plugin: "org.stoyicker.android-check"

Configuration

Recommended

The default one.

Customized

Kotlin
// Configuration is completely optional, defaults will be used if not present
check {
  // Do absolutely nothing, default: false
  skip(true/false)
  // Fails build if a violation is found, default: true. Ignored if all per-tool confs are set to abortOnError false (see below)
  abortOnError(true/false)
  // Checkstyle configuration
  checkstyle {
    // Completely skip Checkstyle, default: false
    skip(true/false)
    // Fails build if Checkstyle rule violations are found, default: false
    abortOnError(true/false)
    // Configuration file for Checkstyle, default: <project_path>/config/checkstyle.xml, if non-existent then <project_path>/<module_path>/config/checkstyle.xml, if non-existent then plugin/src/main/resources/checkstyle/conf-default.xml
    config("path/to/config.xml")
    // Output file for XML reports, default: File(project.buildDir, "outputs/checkstyle/checkstyle.xml")
    reportXML(File(project.buildDir, "path/where/you/want/checkstyle.xml"))
    // Output file for HTML reports, default: File(project.buildDir, "outputs/checkstyle/checkstyle.html")
    reportHTML(File(project.buildDir, "path/where/you/want/checkstyle.html"))
  }
  // PMD configuration
  pmd {
    // Completely skip PMD, default: false
    skip(true/false)
    // Fails build if PMD rule violations are found, default: false
    abortOnError(true/false)
    // Configuration file for PMD, default: <project_path>/config/pmd.xml, if non-existent then <project_path>/<module_path>/config/pmd.xml, if non-existent then plugin/src/main/resources/pmd/conf-default.xml
    config("path/to/config.xml")
    // Output file for XML reports, default: File(project.buildDir, "outputs/pmd/pmd.xml")
    reportXML(File(project.buildDir, "path/where/you/want/pmd.xml"))
    // Output file for HTML reports, default: File(project.buildDir, "outputs/pmd/pmd.html")
    reportHTML(File(project.buildDir, "path/where/you/want/pmd.html"))
  }
}
Groovy
// Configuration is completely optional, defaults will be used if not present
check {
  // Do absolutely nothing, default: false
  skip(true/false)
  // Fails build if a violation is found, default: true. Ignored if all per-tool confs are set to abortOnError false (see below)
  abortOnError(true/false)
  // Checkstyle configuration
  checkstyle {
    // Completely skip Checkstyle, default: false
    skip(true/false)
    // Fails build if Checkstyle rule violations are found, default: false
    abortOnError(true/false)
    // Configuration file for Checkstyle, default: <project_path>/config/checkstyle.xml, if non-existent then <project_path>/<module_path>/config/checkstyle.xml, if non-existent then plugin/src/main/resources/checkstyle/conf-default.xml
    config("path/to/config.xml")
    // Output file for XML reports, default: new File(project.buildDir, "outputs/checkstyle/checkstyle.xml")
    reportXML(new File(project.buildDir, "path/where/you/want/checkstyle.xml"))
    // Output file for HTML reports, default: new File(project.buildDir, "outputs/checkstyle/checkstyle.html")
    reportHTML(new File(project.buildDir, "path/where/you/want/checkstyle.html"))
  }
  // PMD configuration
  pmd {
    // Completely skip PMD, default: false
    skip(true/false)
    // Fails build if PMD rule violations are found, default: false
    abortOnError(true/false)
    // Configuration file for PMD, default: <project_path>/config/pmd.xml, if non-existent then <project_path>/<module_path>/config/pmd.xml, if non-existent then plugin/src/main/resources/pmd/conf-default.xml
    config("path/to/config.xml")
    // Output file for XML reports, default: new File(project.buildDir, "outputs/pmd/pmd.xml")
    reportXML(new File(project.buildDir, "path/where/you/want/pmd.xml"))
    // Output file for HTML reports, default: new File(project.buildDir, "outputs/pmd/pmd.html")
    reportHTML(new File(project.buildDir, "path/where/you/want/pmd.html"))
  }
}

Also, if abortOnError is true, the browser will open the report for the tool that caused the failure (if your system supports it).

Developed By

The original version of this plugin was developed by:

This fork is owned and maintained by Jorge Antonio Diaz-Benito Soriano.

License

See LICENSE.txt.

Original work licensed under MIT license.

About

Static code analysis plugin for next-generation Android projects.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • XSLT 53.3%
  • Groovy 43.6%
  • Shell 3.1%