Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Release #191

Merged
merged 53 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b3a1393
Remove older version support for ktlint
tasomaniac Apr 13, 2019
d755090
Lazy tasks for Detekt
tasomaniac Apr 13, 2019
006d143
Upgrade sample Kotlin version for running tests on Gradle 5
tasomaniac Apr 13, 2019
451ca3b
Lazy tasks for Lint
tasomaniac Apr 13, 2019
77d79d2
Lazy tasks for Pmd
tasomaniac Apr 13, 2019
a52f78c
Lazy tasks for java projects for all Java CodeQuality tools
tasomaniac May 2, 2019
531aedc
Lazy tasks for Android projects for all Java CodeQuality tools
tasomaniac May 2, 2019
758cf8f
Remove last bit of non-lazy task creation
tasomaniac May 2, 2019
eed3a7c
shuffle methods for clarity
tasomaniac May 2, 2019
0597e2d
Configure Findbugs per variant again instead of sourceSets
tasomaniac May 4, 2019
9384b6a
clean-up
tasomaniac May 4, 2019
542432a
Merge branch 'master' into taso/lazy-tasks-except-for-ktlint
tasomaniac May 4, 2019
eb86bc1
Make the meta task name unique per tool
tasomaniac May 4, 2019
3d7df2f
Merge pull request #183 from novoda/taso/remove-afterevaluate
mr-archano May 6, 2019
71058cf
Merge branch 'develop' of github.com:novoda/gradle-static-analysis-pl…
tasomaniac May 8, 2019
1771f1e
Merge branch 'develop' into taso/lazy-tasks-except-for-ktlint
tasomaniac May 8, 2019
78e1e05
Create tasks only once to enable multiple configuration support
tasomaniac May 8, 2019
bf3eace
Add configured trick to Findbugs separately
tasomaniac May 8, 2019
a5b56f9
Use Closure resolve strategy for correctness
tasomaniac May 8, 2019
dbfa74e
SAP automatically configures itself when it detects other tools and p…
tasomaniac May 10, 2019
40247c8
Merge pull request #187 from novoda/taso/optional-check-task
mr-archano May 12, 2019
96c7093
Merge branch 'develop' into taso/lazy-tasks-except-for-ktlint
mr-archano May 12, 2019
bd1c4d7
Merge branch 'develop' into taso/define-closure-strategy
tasomaniac May 12, 2019
c6eb082
Prefer single quote for Strings
tasomaniac May 12, 2019
d18b48e
More clear param name
tasomaniac May 12, 2019
5ae58ca
Reorder methods to better organize
tasomaniac May 12, 2019
4b30fb4
Merge pull request #184 from novoda/taso/lazy-tasks-except-for-ktlint
mr-archano May 13, 2019
dca6979
Merge branch 'develop' into taso/define-closure-strategy
mr-archano May 14, 2019
6d726cc
Merge pull request #185 from novoda/taso/define-closure-strategy
tasomaniac May 14, 2019
488fb2d
Simplify detekt configuration and remove legacy versions support
tasomaniac May 8, 2019
f305f48
Add support for disabling failFast
tasomaniac May 8, 2019
93f9e6b
Update the supported versions information
tasomaniac May 8, 2019
5de354a
Extract checking xml report enabled state
tasomaniac May 14, 2019
621e097
Make check task is also lazy
tasomaniac May 15, 2019
efd78e2
Update versions, dependencies and fix package names
tasomaniac May 15, 2019
2a4068e
Fix task not found issue by getting xml and html report locations fro…
tasomaniac May 15, 2019
2cda960
Merge pull request #186 from novoda/taso/use_new_detekt_features
mr-archano May 15, 2019
c9f37f0
Merge branch 'develop' into taso/update-sample
mr-archano May 15, 2019
7b2c361
Merge pull request #188 from novoda/taso/update-sample
tasomaniac May 16, 2019
581aa77
Change configuration of ktlint task to support lazy tasks
tasomaniac May 16, 2019
2f9085c
Add support for configuration error handling with useful version info…
tasomaniac May 16, 2019
efa8702
Update docs
tasomaniac May 16, 2019
c3d732f
Prepare for release 1.0
tasomaniac May 16, 2019
8369274
Change README to have more information about recent changes.
tasomaniac May 16, 2019
e9bb49a
Merge pull request #189 from novoda/taso/lazy-ktlint
mr-archano May 18, 2019
6684b01
Merge branch 'develop' into prepare-release
mr-archano May 18, 2019
eb1e082
Merge pull request #190 from novoda/prepare-release
mr-archano May 20, 2019
a01746a
Inject bintrayOrg via build properties
mr-archano May 20, 2019
948c014
Update Bintray repos referenced in documentation
mr-archano May 20, 2019
9f8830a
Tweak formatting of error message in buildscript
mr-archano May 20, 2019
0a2e4bb
Use correct build properties set
mr-archano May 20, 2019
49d063a
Merge pull request #192 from novoda/gradle/update_release_script
mr-archano May 20, 2019
2052deb
Fix snapshots badge URL.
mr-archano May 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
Change Log
==========

[Version 1.0](https://github.com/novoda/gradle-static-analysis-plugin/releases/tag/v1.0)
--------------------------

- Add support for task configuration avoidance [PR#184](https://github.com/novoda/gradle-static-analysis-plugin/pull/184) [PR#186](https://github.com/novoda/gradle-static-analysis-plugin/pull/186) [PR#189](https://github.com/novoda/gradle-static-analysis-plugin/pull/189)
- This is a big performance improvement and a recommended upgrade for all users.
- Unless `evaluateViolations` or `check` task is run explicitly, no task will be configured eagerly.
- More info on Gradle: https://docs.gradle.org/current/userguide/task_configuration_avoidance.html
- Removed support for older versions of Ktlint and Detekt
- Minimum supported Ktlint Plugin: `6.2.1`
- Minimum supported Detekt Plugin: `1.0.0.RC9.2`
- Fix: In some cases Groovy closures would use wrong scope [PR#185](https://github.com/novoda/gradle-static-analysis-plugin/pull/185)
- Fix: check task not found on empty project [PR#187](https://github.com/novoda/gradle-static-analysis-plugin/pull/187)
- Detekt is automatically configured to disable failFast since failure is handled by Static Analysis Plugin [PR#186](https://github.com/novoda/gradle-static-analysis-plugin/pull/186)
- Update sample with new versions and make use of task configuration avoidance [PR#188](https://github.com/novoda/gradle-static-analysis-plugin/pull/188)

[Version 0.8.1](https://github.com/novoda/gradle-static-analysis-plugin/releases/tag/v0.8.1)
--------------------------

Expand Down
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Gradle static analysis plugin
[![](https://ci.novoda.com/buildStatus/icon?job=gradle-static-analysis-plugin)](https://ci.novoda.com/job/gradle-static-analysis-plugin/lastSuccessfulBuild) [![](https://img.shields.io/badge/License-Apache%202.0-lightgrey.svg)](LICENSE.txt) [![Bintray](https://api.bintray.com/packages/novoda/maven/gradle-static-analysis-plugin/images/download.svg)](https://bintray.com/novoda/maven/gradle-static-analysis-plugin/_latestVersion)
[![](https://ci.novoda.com/buildStatus/icon?job=gradle-static-analysis-plugin)](https://ci.novoda.com/job/gradle-static-analysis-plugin/lastSuccessfulBuild) [![](https://img.shields.io/badge/License-Apache%202.0-lightgrey.svg)](LICENSE.txt) [![Bintray](https://api.bintray.com/packages/novoda/maven/gradle-static-analysis-plugin/images/download.svg)](https://bintray.com/novoda-oss/maven/gradle-static-analysis-plugin/_latestVersion)

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

Supports [Task Configuration Avoidance](https://docs.gradle.org/current/userguide/task_configuration_avoidance.html) so that you have zero overhead in build speeds when you use this plugin!

## Description
Gradle supports many popular static analysis (Checkstyle, PMD, FindBugs, 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
Expand All @@ -17,16 +19,25 @@ The `gradle-static-analysis-plugin` aims to provide:
### Supported tools
The plugin supports various static analysis tools for Java, Kotlin and Android projects:

* [`Checkstyle`](https://checkstyle.sourceforge.net)
* [`PMD`](https://pmd.github.io)
* [`FindBugs`](http://findbugs.sourceforge.net/)
* [`Detekt`](https://github.com/arturbosch/detekt)
* [`Android Lint`](https://developer.android.com/studio/write/lint.html)
* [`KtLint`](https://github.com/shyiko/ktlint)
* [`Checkstyle`](docs/tools/checkstyle.md)
* [`PMD`](docs/tools/pmd.md)
* [`FindBugs`](docs/tools/findbugs.md)
* [`Detekt`](docs/tools/detekt.md)
* [`Android Lint`](docs/tools/android_lint.md)
* [`KtLint`](docs/tools/ktlint.md)

Please note that the tools availability depends on the project the plugin is applied to. For more details please refer to the
[supported tools](docs/supported-tools.md) page.

### Tools in-consideration

* `Spotbugs` [#142](https://github.com/novoda/gradle-static-analysis-plugin/issues/142)
* `CPD (Duplicate Code Detection) ` [#150](https://github.com/novoda/gradle-static-analysis-plugin/iss (Duplicate Code Detection) ues/150)
* `error-prone` [#151](https://github.com/novoda/gradle-static-analysis-plugin/issues/151)
* `Jetbrains IDEA Inspections` [#152](https://github.com/novoda/gradle-static-analysis-plugin/issues/152)

For all tools in consideration, please refer to [issues](https://github.com/novoda/gradle-static-analysis-plugin/issues?q=is%3Aissue+is%3Aopen+label%3A%22new+tool%22).

### 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 `gradle-static-analysis-plugin` to your Android project will make sure all the necessary tasks are created and correctly configured
Expand Down Expand Up @@ -81,19 +92,19 @@ This will enable all the tools with their default settings. For more advanced co
There are two sample Android projects available, one consisting of a regular app - available [here](https://github.com/novoda/gradle-static-analysis-plugin/tree/master/sample) - and the other comprising a multi-module setup available [here](https://github.com/novoda/gradle-static-analysis-plugin/tree/master/sample-multi-module). Both sample projects showcase a setup featuring Checkstyle, FindBugs, PMD, Lint and Detekt.

## Snapshots
[![CI status](https://ci.novoda.com/buildStatus/icon?job=gradle-static-analysis-plugin-snapshot)](https://ci.novoda.com/job/gradle-static-analysis-plugin-snapshot/lastBuild/console) [![Download from Bintray](https://api.bintray.com/packages/novoda/snapshots/gradle-static-analysis-plugin/images/download.svg)](https://bintray.com/novoda/snapshots/gradle-static-analysis-plugin/_latestVersion)
[![CI status](https://ci.novoda.com/buildStatus/icon?job=gradle-static-analysis-plugin-snapshot)](https://ci.novoda.com/job/gradle-static-analysis-plugin-snapshot/lastBuild/console) [![Download from Bintray](https://api.bintray.com/packages/novoda-oss/snapshots/gradle-static-analysis-plugin/images/download.svg)](https://bintray.com/novoda-oss/snapshots/gradle-static-analysis-plugin/_latestVersion)

Snapshot builds from [`develop`](https://github.com/novoda/gradle-static-analysis-plugin/compare/master...develop) are automatically deployed to a [repository](https://bintray.com/novoda/snapshots/gradle-static-analysis-plugin/_latestVersion) that is not synced with JCenter.
Snapshot builds from [`develop`](https://github.com/novoda/gradle-static-analysis-plugin/compare/master...develop) are automatically deployed to a [repository](https://bintray.com/novoda-oss/snapshots/gradle-static-analysis-plugin/_latestVersion) that is not synced with JCenter.
To consume a snapshot build add an additional maven repo as follows:
```
repositories {
maven {
url 'https://novoda.bintray.com/snapshots'
url 'https://dl.bintray.com/novoda-oss/snapshots/'
}
}
```

You can find the latest snapshot version following this [link](https://bintray.com/novoda/snapshots/gradle-static-analysis-plugin/_latestVersion).
You can find the latest snapshot version following this [link](https://bintray.com/novoda-oss/snapshots/gradle-static-analysis-plugin/_latestVersion).

## Roadmap
The plugin is under active development and to be considered in **beta stage**. It is routinely used by many Novoda projects and
Expand Down
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
1. Execute the [build job](https://ci.novoda.com/job/gradle-static-analysis-plugin/) manually with `BINTRAY_DRY_RUN=false`.
1. After the release is successful do a manual [github release](https://github.com/novoda/gradle-static-analysis-plugin/releases) with the newly created tag.

This releases the plugin to [bintray](https://bintray.com/novoda/maven/gradle-static-analysis-plugin) and the [Gradle Plugins Repository](https://plugins.gradle.org/plugin/com.novoda.static-analysis).
This releases the plugin to [bintray](https://bintray.com/novoda-oss/maven/gradle-static-analysis-plugin) and the [Gradle Plugins Repository](https://plugins.gradle.org/plugin/com.novoda.static-analysis).
21 changes: 11 additions & 10 deletions docs/tools/detekt.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
does not support Java. It can be used in both pure Kotlin, and Android Kotlin projects. It then only makes sense to have Detekt enabled if you
have Kotlin code in your project. The plugin only runs Detekt on projects that contain the Kotlin or the Kotlin-Android plugin.

> Supported Detekt Gradle Plugin version: **1.0.0.RC9.2 and above**
> Recommended Detekt Gradle Plugin version: **1.0.0-RC14 and above**

## Table of contents
* [IMPORTANT: setup Detekt](#important-setup-detekt)
* [Configure Detekt](#configure-detekt)
Expand All @@ -25,7 +28,7 @@ In most common cases, adding Detekt to a project boils down to three simple step
1. Add this statement to your root `build.gradle` project (change the version according to your needs):
```gradle
plugins {
id 'io.gitlab.arturbosch.detekt' version '1.0.0.RC6-2'
id 'io.gitlab.arturbosch.detekt' version '1.0.0-RC14'
// ...
}
```
Expand All @@ -39,17 +42,15 @@ In most common cases, adding Detekt to a project boils down to three simple step

## Configure Detekt
Enabling and configuring Detekt for a project is done through the `detekt` closure. The closure behaves exactly like the
[standard Detekt plugin](https://github.com/arturbosch/detekt#using-the-detekt-gradle-plugin) does in Gradle, which is to say, quite differently
[standard Detekt plugin](https://github.com/arturbosch/detekt#with-gradle) does in Gradle, which is to say, quite differently
from how the other tools' configurations closures work. For example:

```gradle
detekt {
profile('main') {
input = // A string pointing to a project's sources. E.g., "$projectDir/src/main/java"
config = // A file containing the Detekt configuration, e.g., teamPropsFile('static-analysis/detekt-config.yml')
filters = // A comma-separated list of regex exclusions, e.g., '.*test.*,.*/resources/.*,.*/tmp/.*'
output = // A string pointing to the output directory for the reports, e.g., "$projectDir/build/reports/detekt"
}
toolVersion = "[version]" // custom toolVersion defined. By default, it is the Gradle plugin version
input = files("src/main/kotlin") // Optional: files representing project's Kotlin sources
filters = ".*/resources/.*,.*/build/.*" // A comma-separated list of regex exclusions
baseline = file("my-detekt-baseline.xml") // Optional: Just if you want to create a baseline file.
}
```

Expand All @@ -59,7 +60,7 @@ You need to provide **at a minimum** the `config` and `output` values. It's impo
in the Detekt configuration file as it will interfere with the functioning of the Static Analysis plugin's threshold counting. For the same reason, make
sure that `failFast` is set to `false` in the Detekt configuration.

For more informations about Detekt rules, refer to the [official website](https://github.com/arturbosch/detekt/tree/master/detekt-generator/documentation).
For more information about Detekt rules, refer to the [official website](https://arturbosch.github.io/detekt/#quick-start-with-gradle).

## Exclude files from Detekt analysis

Expand All @@ -71,4 +72,4 @@ The `filters` property expects a string consisting in a comma-separated list of

## Detekt in mixed-language projects
If your project mixes Java and Kotlin code, you don't need to have an exclusion in place for all `*.java` files. Detekt itself only looks for
`*.kt` files, so no further configuration is required.
`*.kt` files, so no further configuration is required.
4 changes: 3 additions & 1 deletion docs/tools/ktlint.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
[Ktlint](https://github.com/shyiko/ktlint) is a linter for Kotlin with a built-in formatter. It does not support Java. Adding
this tool only makes sense when you have Kotlin sources in your project.

> Supported Ktlint Gradle Plugin version: **6.2.1 and above**

## Table of contents
* [IMPORTANT: setup Ktlint](#important-setup-ktlint)
* [Configure Ktlint](#configure-ktlint)
Expand All @@ -24,7 +26,7 @@ In most common cases, adding Ktlint to a project boils down to these simple step
1. Add this statement to your root `build.gradle` project (change the version according to your needs):
```gradle
plugins {
id 'org.jlleitschuh.gradle.ktlint' version '5.1.0'
id 'org.jlleitschuh.gradle.ktlint' version '7.3.0'
// ...
}
```
Expand Down
30 changes: 16 additions & 14 deletions gradle/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ext {
websiteUrl = 'https://github.com/novoda/gradle-static-analysis-plugin'
}

version = '0.8.1'
version = '1.0'
groovydoc.docTitle = 'Static Analysis Plugin'

apply plugin: 'com.novoda.build-properties'
Expand All @@ -14,13 +14,13 @@ buildProperties {

secrets {
using rootProject.file('secrets.properties')
description = '''
This file should contain:
- git.username: the username used to push to the repo
- git.password: the password used to push to the repo
- gradle.publish.key: the key to publish the plugin to the Gradle Plugins Repository
- gradle.publish.secret: the secret to publish the plugin to the Gradle Plugins Repository
'''
description = '''This file should contain:
- git.username: the username used to push to the repo
- git.password: the password used to push to the repo
- gradle.publish.key: the key to publish the plugin to the Gradle Plugins Repository
- gradle.publish.secret: the secret to publish the plugin to the Gradle Plugins Repository'''
.stripIndent()

}

cli {
Expand All @@ -30,14 +30,16 @@ buildProperties {
bintray {
def bintrayCredentials = {
return isDryRun() ?
['bintrayRepo': 'n/a', 'bintrayUser': 'n/a', 'bintrayKey': 'n/a'] :
['bintrayOrg': 'n/a', 'bintrayRepo': 'n/a', 'bintrayUser': 'n/a', 'bintrayKey': 'n/a'] :
new File("${System.getenv('BINTRAY_PROPERTIES')}")
}
using(bintrayCredentials()).or(cli)
description = '''This should contain the following properties:
- bintrayRepo: name of the repo of the organisation to deploy the artifacts to
- bintrayUser: name of the account used to deploy the artifacts
- bintrayKey: API key of the account used to deploy the artifacts'''.stripIndent()
- bintrayOrg: name of the Bintray organisation to deploy the artifacts to
- bintrayRepo: name of the repo of the organisation to deploy the artifacts to
- bintrayUser: name of the account used to deploy the artifacts
- bintrayKey: API key of the account used to deploy the artifacts'''
.stripIndent()
}

}
Expand All @@ -46,13 +48,13 @@ apply plugin: 'com.gradle.plugin-publish'
apply plugin: 'com.novoda.bintray-release'

publish {
userOrg = 'novoda'
groupId = 'com.novoda'
artifactId = 'gradle-static-analysis-plugin'
desc = 'Easy setup of static analysis tools for Android and Java projects.'
publishVersion = buildVersion

repoName = project.buildProperties.bintray['bintrayRepo'].string
userOrg = project.buildProperties.bintray['bintrayOrg'].string
bintrayUser = project.buildProperties.bintray['bintrayUser'].string
bintrayKey = project.buildProperties.bintray['bintrayKey'].string
website = project.websiteUrl
Expand Down Expand Up @@ -200,7 +202,7 @@ boolean isSnapshot() {
}

String getBuildVersion() {
return isSnapshot() ? "SNAPSHOT-${System.getenv('BUILD_NUMBER') ?: 'LOCAL'}" : project.version
return isSnapshot() ? "DEVELOP-${System.getenv('BUILD_NUMBER') ?: 'LOCAL'}" : project.version
}

String getTag() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.novoda.staticanalysis

import com.novoda.staticanalysis.internal.CodeQualityConfigurator
import com.novoda.staticanalysis.internal.Configurator
import com.novoda.staticanalysis.internal.checkstyle.CheckstyleConfigurator
import com.novoda.staticanalysis.internal.detekt.DetektConfigurator
import com.novoda.staticanalysis.internal.findbugs.FindbugsConfigurator
Expand All @@ -12,15 +12,17 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task

import static com.novoda.staticanalysis.internal.TasksCompat.configureEach

class StaticAnalysisPlugin implements Plugin<Project> {

@Override
void apply(Project project) {
def pluginExtension = project.extensions.create('staticAnalysis', StaticAnalysisExtension, project)
def evaluateViolations = createEvaluateViolationsTask(project, pluginExtension)
createConfigurators(project, pluginExtension, evaluateViolations).each { configurator -> configurator.execute() }
project.afterEvaluate {
project.tasks['check'].dependsOn evaluateViolations
configureEach(project.tasks.matching { it.name == 'check' }) { task ->
task.dependsOn evaluateViolations
}
}

Expand All @@ -32,9 +34,9 @@ class StaticAnalysisPlugin implements Plugin<Project> {
}
}

private static List<CodeQualityConfigurator> createConfigurators(Project project,
StaticAnalysisExtension pluginExtension,
Task evaluateViolations) {
private static List<Configurator> createConfigurators(Project project,
StaticAnalysisExtension pluginExtension,
Task evaluateViolations) {
NamedDomainObjectContainer<Violations> violationsContainer = pluginExtension.allViolations
[
CheckstyleConfigurator.create(project, violationsContainer, evaluateViolations),
Expand Down