forked from ffgiff/gradle-init-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathktlint-init.groovy
37 lines (35 loc) · 1.06 KB
/
ktlint-init.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import org.gradle.api.Project
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.shyiko:ktlint:0.19.0'
}
}
gradle.projectsEvaluated {
ext.applyKtlint = {
if (project.hasProperty('android')) {
addKtlintTask(project)
project.check.dependsOn project.tasks.ktlint
}
}
if (rootProject.subprojects.isEmpty()) {
rootProject applyKtlint
} else {
rootProject.subprojects applyKtlint
}
}
void addKtlintTask(final Project project) {
ext.source = ['main', 'androidTest', 'test'].collect {
project.android.sourceSets.findByName(it)
}.find { null != it }.collect { it.java.srcDirs }
project.tasks.create([name:'ktlint', type:JavaExec, group:'verification']) {
args '--android'
classpath files(buildscript.scriptClassPath.asFiles)
description 'Check Kotlin code style.'
ignoreExitValue true
main 'com.github.shyiko.ktlint.Main'
source.each { args "${it.absolutePath}/**/*.kt" }
}
}