Merge pull request #9977 from nextcloud/chore/ktlint-gradle

Use ktlint plugin instead of manual ktlint tasks
This commit is contained in:
Álvaro Brey 2022-03-16 13:05:23 +01:00 committed by GitHub
commit b70eeaae3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 22 deletions

View file

@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
task: [ detekt, ktlint ]
task: [ detekt, ktlintCheck ]
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11

View file

@ -13,6 +13,7 @@ buildscript {
classpath "org.jacoco:org.jacoco.core:$jacoco_version"
classpath "org.jacoco:org.jacoco.report:$jacoco_version"
classpath "org.jacoco:org.jacoco.agent:$jacoco_version"
classpath "org.jlleitschuh.gradle:ktlint-gradle:10.2.1"
}
}
@ -27,12 +28,11 @@ apply plugin: 'com.hiya.jacoco-android'
apply plugin: 'com.github.spotbugs'
apply plugin: 'io.gitlab.arturbosch.detekt'
apply plugin: 'shot'
apply plugin: "org.jlleitschuh.gradle.ktlint"
println "Gradle uses Java ${Jvm.current()}"
configurations {
ktlint
all {
exclude group: 'org.jetbrains', module: 'annotations-java5' // via prism4j, already using annotations explicitly
@ -194,7 +194,7 @@ android {
}
}
check.dependsOn 'checkstyle', 'spotbugsGplayDebugReport', 'pmd', 'lint', 'ktlint', 'detekt'
check.dependsOn 'checkstyle', 'spotbugsGplayDebug', 'pmd', 'lint', 'ktlintCheck', 'detekt'
buildFeatures {
dataBinding true
@ -272,7 +272,6 @@ dependencies {
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
ktlint "com.pinterest:ktlint:0.44.0"
implementation 'org.conscrypt:conscrypt-android:2.5.2'
implementation "com.google.android.exoplayer:exoplayer:$exoplayerVersion"
@ -400,20 +399,6 @@ tasks.register("combinedTestReport", JacocoReport) {
])
}
task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
main = "com.pinterest.ktlint.Main"
classpath = configurations.ktlint
args "--reporter=plain", "--reporter=plain,output=${buildDir}/ktlint.txt,${projectDir}/src/**/*.kt"
}
task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
main = "com.pinterest.ktlint.Main"
classpath = configurations.ktlint
args "-F", "${projectDir}/src/**/*.kt"
}
task installGitHooks(type: Copy, group: "development") {
description = "Install git hooks"
from("${project.rootDir}/scripts/hooks") {

View file

@ -1,9 +1,9 @@
#!/bin/bash
# Pre-commit hook: don't allow commits if detekt or ktlint fail. Skip with "git commit --no-verify".
echo "Running pre-commit checks."
echo "Running pre-commit checks..."
if ! ./gradlew --daemon ktlint &>/dev/null; then
echo >&2 "Lint failed! See report at file://$(pwd)/app/build/ktlint.txt"
if ! ./gradlew --daemon ktlintCheck &>/dev/null; then
echo >&2 "ktlint failed! Run ./gradlew ktlintCheck for details"
echo >&2 "Hint: fix most lint errors with ./gradlew ktlintFormat"
exit 1
fi