Skip to content

Commit

Permalink
integrate ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
noboru-i committed Mar 15, 2018
1 parent f866706 commit 57abf89
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 9 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ jobs:
- vendor/bundle

- run:
name: Lint / Test
command: ./gradlew --stacktrace :app:check
- run:
name: Run Danger
command: bundle exec danger
name: Lint
command: |
./gradlew --stacktrace ktlintCheck
./gradlew --stacktrace lint
bundle exec danger
- run:
name: Build apk
Expand Down
10 changes: 10 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ end

# Warn when there is a big PR
warn('a large PR') if git.lines_of_code > 300

# ktlint
checkstyle_format.base_path = Dir.pwd
checkstyle_format.report 'app/build/reports/ktlint/ktlint-debug.xml'

# AndroidLint
android_lint.report_file = "app/build/reports/lint-results.xml"
android_lint.skip_gradle_task = true
android_lint.severity = "Error"
android_lint.lint(inline_mode: true)
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ source "https://rubygems.org"

gem 'danger'
gem 'danger-checkstyle_format'
gem "danger-android_lint"
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ GEM
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ansi (1.5.0)
ast (2.4.0)
claide (1.0.2)
claide-plugins (0.9.2)
cork
Expand All @@ -23,6 +25,9 @@ GEM
no_proxy_fix
octokit (~> 4.7)
terminal-table (~> 1)
danger-android_lint (0.0.6)
danger-plugin-api (~> 1.0)
oga
danger-checkstyle_format (0.1.1)
danger-plugin-api (~> 1.0)
ox (~> 2.0)
Expand All @@ -39,9 +44,15 @@ GEM
no_proxy_fix (0.1.2)
octokit (4.8.0)
sawyer (~> 0.8.0, >= 0.5.3)
oga (2.14)
ast
ruby-ll (~> 2.1)
open4 (1.3.4)
ox (2.9.0)
public_suffix (3.0.2)
ruby-ll (2.1.2)
ansi
ast
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
Expand All @@ -54,6 +65,7 @@ PLATFORMS

DEPENDENCIES
danger
danger-android_lint
danger-checkstyle_format

BUNDLED WITH
Expand Down
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Sample for Android (Kotlin)

[![CircleCI](https://circleci.com/gh/noboru-i/sample-android-java.svg?style=svg)](https://circleci.com/gh/noboru-i/sample-android-kotlin)

This is the sample continuous integrated project for Android (Kotlin).

## What is this repository?

- **Lint**
- **ktlint**
- **Android Lint**
- **Build**: Configured build setting. e.g. `signingConfigs`, `buildTypes`
- **CircleCI**: Lint, Test, and Build in [CircleCI](https://circleci.com/).
- **PR Comment by Danger**: [Danger](http://danger.systems/ruby/) configuration is included. Lint error comes as PR comment.


## How to setup

1. Setup CircleCI build.
- Turn "On" "Only build pull requests".
2. Copy or refer to below files. [diff](https://github.com/noboru-i/sample-android-kotlin/compare/6e14739b8d26c11b66d3e0c11478fbe84b479ebc...master)
- `.circleci/config.yml`
- `Dangerfile`
- `Gemfile`
- `Gemfile.lock` : If you want newer version, please exec `bundle update`.
- `app/build.gradle`
- `app/keystores/debug.keystore` : Please get from local.
- `app/keystores/release.jks` : Please get or create.
2. Set environment variable.
- `DANGER_GITHUB_API_TOKEN` : token for check bot
- `ANDROID_KEYSTORE_PASSWORD` : password for release keystore
- `ANDROID_KEYSTORE_ALIAS` : alias for release keystore
- `ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD` : alias's password for release keystore

## Customize

This repository is targeting for very simple project.

But in real world, we need to work for complex project.

We have some advice for customizing configuration in [Wiki](https://github.com/noboru-i/sample-android-kotlin/wiki).
Please refer to it.
10 changes: 8 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: "org.jlleitschuh.gradle.ktlint"

android {
compileSdkVersion 27
Expand All @@ -23,6 +22,13 @@ android {
}
}

ktlint {
version = "0.15.0"
android = true
reporters = org.jlleitschuh.gradle.ktlint.reporter.ReporterType.CHECKSTYLE
ignoreFailures = true
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ buildscript {
repositories {
google()
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath "gradle.plugin.org.jlleitschuh.gradle:ktlint-gradle:3.1.0"
}
}

Expand Down

0 comments on commit 57abf89

Please sign in to comment.