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

Commit

Permalink
Merge pull request #126 from novoda/develop
Browse files Browse the repository at this point in the history
Release 0.6
  • Loading branch information
tasomaniac authored Aug 21, 2018
2 parents 7d53175 + c3d483d commit 5db6778
Show file tree
Hide file tree
Showing 48 changed files with 672 additions and 195 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
Change Log
==========

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

- Fix release to plugin portal ([PR#82](https://github.com/novoda/gradle-static-analysis-plugin/pull/82),[PR#83](https://github.com/novoda/gradle-static-analysis-plugin/pull/83))
- Improve plugin documentation and samples ([PR#85](https://github.com/novoda/gradle-static-analysis-plugin/pull/85),
[PR#97](https://github.com/novoda/gradle-static-analysis-plugin/pull/97),
[PR#99](https://github.com/novoda/gradle-static-analysis-plugin/pull/99),
[PR#100](https://github.com/novoda/gradle-static-analysis-plugin/pull/100),
[PR#101](https://github.com/novoda/gradle-static-analysis-plugin/pull/101),
[PR#113](https://github.com/novoda/gradle-static-analysis-plugin/pull/113),
[PR#123](https://github.com/novoda/gradle-static-analysis-plugin/pull/123),
[PR#124](https://github.com/novoda/gradle-static-analysis-plugin/pull/124))
- Improve support for Android Lint ([PR#105](https://github.com/novoda/gradle-static-analysis-plugin/pull/105))
- Improve support for Detekt ([PR#90](https://github.com/novoda/gradle-static-analysis-plugin/pull/90), [PR#121](https://github.com/novoda/gradle-static-analysis-plugin/pull/121))
- Rename built-in `failOnWarnings` penalty to `failFast` ([PR#92](https://github.com/novoda/gradle-static-analysis-plugin/pull/92))
- Support multiple configurations for `Pmd`, `Findbugs`, `Checkstyle` ([PR#93](https://github.com/novoda/gradle-static-analysis-plugin/pull/93))
- Support automatic snapshot builds from `develop` ([PR#106](https://github.com/novoda/gradle-static-analysis-plugin/pull/106),[PR#107](https://github.com/novoda/gradle-static-analysis-plugin/pull/107))
- Automatically exclude Kotlin files from Java code quality tools ([PR#109](https://github.com/novoda/gradle-static-analysis-plugin/pull/109))
- Integrate [KtLint](https://github.com/shyiko/ktlint) ([PR#110](https://github.com/novoda/gradle-static-analysis-plugin/pull/110))

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

Expand Down
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ The plugin supports various static analysis tools for Java, Kotlin and Android p
* [`FindBugs`](http://findbugs.sourceforge.net/)
* [`Detekt`](https://github.com/arturbosch/detekt)
* [`Android Lint`](https://developer.android.com/studio/write/lint.html)

Support for additional tools is planned but not available yet:

* [`KtLint`](https://github.com/shyiko/ktlint)

Please note that the tools availability depends on the project the plugin is applied to. For more details please refer to the
Expand All @@ -44,7 +41,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.novoda:gradle-static-analysis-plugin:0.5.2'
classpath 'com.novoda:gradle-static-analysis-plugin:0.6'
}
}
Expand All @@ -55,7 +52,7 @@ or from the [Gradle Plugins Repository](https://plugins.gradle.org/):

```gradle
plugins {
id 'com.novoda.static-analysis' version '0.5.2'
id 'com.novoda.static-analysis' version '0.6'
}
```
Expand Down Expand Up @@ -83,6 +80,21 @@ This will enable all the tools with their default settings. For more advanced co
## Sample app
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)

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.
To consume a snapshot build add an additional maven repo as follows:
```
repositories {
maven {
url 'https://novoda.bintray.com/snapshots'
}
}
```

You can find the latest snapshot version following this [link](https://bintray.com/novoda/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
by other external projects with no known critical issues. The API is supposed to be relatively stable, but there still may be
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/groovy/GradlePlugins.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class GradlePlugins {
final bintrayRelease = 'com.novoda:bintray-release:0.4.0'
final buildProperties = 'com.novoda:gradle-build-properties-plugin:0.2'
final buildProperties = 'com.novoda:gradle-build-properties-plugin:0.4.1'
final gradleGit = 'org.ajoberstar:gradle-git:1.6.0'
final gradlePublish = 'com.gradle.publish:plugin-publish-plugin:0.9.9'
}
72 changes: 70 additions & 2 deletions docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ the build will not fail, which is very useful for legacy projects.
* [Improve the report with a base URL](#improve-the-report-with-a-base-URL)
* [Add exclusions with `exclude` filters](#add-exclusions-with-exclude-filters)
* [Add exclusions with Android build variants](#add-exclusions-with-android-build-variants)
* [Consume rules from an artifact](#consume-rules-from-an-artifact)
* [Custom violations evaluator (**incubating**)](incubating/custom-evaluator.md#custom-violations-evaluator-incubating)

---
Expand Down Expand Up @@ -50,10 +51,10 @@ Besides manually specifying thresholds, the plugin includes a few built-in `pena
```
This will break the build if any error is found. Warnings instead are only logged and will not break the build.
* `failOnWarnings`
* `failFast`
```gradle
staticAnalysis {
penalty failOnWarnings
penalty failFast
}
```
This policy will fail the build if any warning or error is found. It is a zero-tolerance policy, useful to keep
Expand Down Expand Up @@ -131,3 +132,70 @@ staticAnalysis {
Please note that this is not yet supported for Detekt.

[penaltyextensioncode]: https://github.com/novoda/gradle-static-analysis-plugin/blob/master/plugin/src/main/groovy/com/novoda/staticanalysis/PenaltyExtension.groovy


## Consume rules from an artifact
In order to reuse your rules among multiple projects or to easily use an open source rule set, we added support for consuming the
rules for all supported tools from a Maven artifact.

### Rules artifact
A rule artifact is just a bundle of files that is published on a Maven repository as artifact. An example of how to do that can be be found [here](https://github.com/novoda/novoda/blob/master/scaffolding/build.gradle).
In this case we bundle the files as jar using the using the [java plugin](https://docs.gradle.org/current/userguide/java_plugin.html) and publish it using our [bintray-release plugin](https://github.com/novoda/bintray-release).

### How to define a dependency from a rules artifact
In order to access the files inside a rule artifact you have to first define an entry in the `rules {}` extension of the plugin. An entry is defined by a name and a Maven coordinate, as follows:
```
staticAnalysis {
rules {
novoda {
maven 'com.novoda:static-analysis-rules:0.2'
}
}
}
```

### Access rules from artifact
Once you have defined a rule artifact you can access the files inside it specifying the path of the file inside the bundle, e.g.:
```
def modules = rules.novoda['checkstyle-modules.xml']
```
Note that `modules` is defined as [`TextResource`](https://docs.gradle.org/current/dsl/org.gradle.api.resources.TextResource.html), that is a read-only body of text backed by a string, file, archive entry, or other source. Some of the tools already accept `TextResource` as value for some of their configuration, while in other cases you have to transform a `TextResource` into a `File` or a path. Some examples of using a rule artifact in the supported tools is provided below:

#### Checkstyle
```gradle
checkstyle {
toolVersion '8.8'
config rules.novoda['checkstyle-modules.xml']
}
```

#### PMD
```gradle
pmd {
toolVersion '6.0.1'
ruleSetFiles = project.files(rules.novoda['pmd-rules.xml'].asFile().path)
}
```

#### FindBugs
```gradle
findbugs {
excludeFilter rules.novoda['findbugs-excludes.xml'].asFile()
}
```

#### Detekt
```gradle
detekt {
profile('main') {
config = rules.novoda['detekt.yml'].asFile().path
}
}
```

#### Android Lint
```gradle
lintOptions {
lintConfig = rules.novoda['lint-config.xml'].asFile()
}
```
8 changes: 4 additions & 4 deletions docs/supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ Tool | Java | Android<br/>(Java) | Kotlin | Android<br/>(Kotlin)
[`FindBugs`](http://findbugs.sourceforge.net/) | :white_check_mark: | :white_check_mark: | — | —
[`Detekt`](https://github.com/arturbosch/detekt) | — | — | :white_check_mark: | :white_check_mark:
[`Android Lint`](https://developer.android.com/studio/write/lint.html) | — | :white_check_mark:️ | — | :white_check_mark:
[`KtLint`\*](https://github.com/shyiko/ktlint) | — | — | ✖️ | ✖️

_\* Not supported [yet](https://github.com/novoda/gradle-static-analysis-plugin/issues?q=is%3Aopen+is%3Aissue+label%3A%22new+tool%22)_
[`KtLint`](https://github.com/shyiko/ktlint) | — | — | :white_check_mark:️ | :white_check_mark:

For additional informations and tips on how to obtain advanced behaviours with the plugin and its tools, please refer to the
[advanced usage](advanced-usage.md) page.
Expand All @@ -25,7 +23,7 @@ For additional informations and tips on how to obtain advanced behaviours with t
* [PMD](tools/pmd.md)
* [Findbugs](tools/findbugs.md)
* [Android Lint](tools/android_lint.md)
* KtLint_COMING SOON_
* [KtLint](tools/ktlint.md)
* [Example configurations](#example-configurations)

---
Expand All @@ -42,7 +40,9 @@ staticAnalysis {
checkstyle {}
pmd {}
findbugs {}
lintOptions {}
detekt {}
ktlint {}
}
```

Expand Down
20 changes: 1 addition & 19 deletions docs/tools/findbugs.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,4 @@ You can have multiple `exclude` statements.
For more informations about Findbugs rules, refer to the [official website](http://findbugs.sourceforge.net/bugDescriptions.html).

## Findbugs in mixed-language projects
If your project mixes Java and Kotlin code, you most likely want to have an exclusion in place for all `*.kt` files. You can use the `exclude`
in the configuration closure, or you can do so by adding a suppression to the filter file:

`findbugs-excludes.xml`
```xml
<FindBugsFilter>

...

<Match>
<Source name="~.*\.kt" />
</Match>

...

</FindBugsFilter>
```


If your project mixes Java and Kotlin code, your Kotlin source files will automatically be ignored.
58 changes: 58 additions & 0 deletions docs/tools/ktlint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# ktlint
[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. In fact, it will fail to run if you have 0 Kotlin
files.

## Table of contents
* [IMPORTANT: setup Ktlint](#important-setup-ktlint)
* [Configure Ktlint](#configure-ktlint)
---

## IMPORTANT: setup Ktlint

Unlike the other tools, the plugin **won't automatically add Ktlint** to your project. If you forget to do it, the plugin will
fail the build with an error.

In order to integrate Ktlint easily we choose to use the [Ktlint Gradle plugin](https://github.com/JLLeitschuh/ktlint-gradle/).
This plugin has a very good understanding of Android source sets and build flavors. You can refer to the
[official documentation](https://github.com/JLLeitschuh/ktlint-gradle/#how-to-use) for further details.

Note that you should _not_ add the `ktlint` closure to your `build.gradle`s, unlike what the official documentation says. The
`ktlint` closure in the `staticAnalysis` configuration gets applied to all Kotlin modules automatically.

In most common cases, adding Ktlint to a project boils down to these simple steps:

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.0.0'
// ...
}
```
2. Add this statement to each Kotlin project's `build.gradle`s:
```gradle
plugins {
id 'org.jlleitschuh.gradle.ktlint'
// ...
}
```
## Configure Ktlint
Unlike other tools, Ktlint does not offer much configuration. By default, it applies
[Kotlin style guide](https://kotlinlang.org/docs/reference/coding-conventions.html) or
[Android Kotlin style guide](https://android.github.io/kotlin-guides/style.html).
To use Android style guide:
```gradle
ktlint {
android true
}
```

For other configuration options and adding custom rules, refer to the
[official guide](https://github.com/JLLeitschuh/ktlint-gradle/#configuration).

**Note:** Failures and threshold detection is handled by Static Analysis plugin. That is why `ignoreFailures = true` is set by
the plugin. Please do not manually override `ignoreFailures` property.
Loading

0 comments on commit 5db6778

Please sign in to comment.