Skip to content

Easy and consistent setup of static analysis tools for Android and Java projects.

License

Notifications You must be signed in to change notification settings

GradleUp/static-analysis-plugin

Gradle static analysis plugin

Test

A Gradle plugin to easily apply the same setup of static analysis tools across different Android, Java or Kotlin projects.

Supports Task Configuration Avoidance so that you have zero overhead in build speeds when you use this plugin!

Description

Gradle supports many popular static analysis (Checkstyle, PMD, SpotBugs, etc) via a set of built-in plugins. Using these plugins in an Android module will require an additional setup to compensate for the differences between the model adopted by the Android plugin compared to the Java one.

The static-analysis-plugin aims to provide:

  • flexible, configurable penalty strategy for builds
  • easy, Android-friendly integration for all static analysis
  • convenient way of sharing same setup across different projects
  • healthy, versionable and configurable defaults

Supported tools

The plugin supports various static analysis tools for Java, Kotlin and Android projects:

Please note that the tools availability depends on the project the plugin is applied to. For more details please refer to the supported tools page.

Tools in-consideration

  • CPD (Duplicate Code Detection)
  • error-prone
  • Jetbrains IDEA Inspections

For all tools in consideration, please refer to issues.

Out-of-the-box support for Android projects

Android projects use a Gradle model that is not compatible with the Java one, supported by the built-in static analysis tools plugins. Applying com.gradleup.static-analysis Plugin to your Android project will make sure all the necessary tasks are created and correctly configured without any additional hassle.

Add the plugin to your project

Gradle Plugin Portal

Add the plugin in build.gradle(.kts) file

plugins {
    id("com.gradleup.static-analysis") version "<latest-version>"
}

Or apply the plugin from Gradle plugin portal as a classpath dependency

buildscript {
    repositories {
       gradlePluginPortal()
    }
    dependencies {
        classpath("com.gradleup:static-analysis-plugin:<latest-version>")
    }
}

apply plugin: 'com.gradleup.static-analysis'

Simple usage

A typical configuration for the plugin will look like:

staticAnalysis {
    penalty {
        maxErrors = 0
        maxWarnings = 0
    }
    checkstyle { }
    pmd { }
    spotbugs { }
    detekt { }
    lintOptions { }
}

This will enable all the tools with their default settings and create evaluateViolations task. Running ./gradlew evaluateViolations task will run all configured tools and print the reports to console. For more advanced configurations, please refer to the advanced usage and to the supported tools pages.

Sample app

There are two sample Android projects available, one consisting of a regular app - available here - and the other comprising a multi-module setup available here. Both sample projects showcase a setup featuring Checkstyle, SpotBugs, PMD, Lint, Ktlint and Detekt.

License

This project is forked from its original location by the original authors https://github.com/novoda/gradle-static-analysis-plugin

Copyright 2020 The GradleUp Authors

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.

About

Easy and consistent setup of static analysis tools for Android and Java projects.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published