aboutsummaryrefslogtreecommitdiff
path: root/buildSrc/src/main/kotlin/SpotlessConfiguration.kt
blob: 71cfc558a22ecc0a9e74905e1640d7ea1c59dea9 (about) (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Copyright © 2014-2019 The Android Password Store Authors. All Rights Reserved.
 * SPDX-License-Identifier: GPL-2.0
 */
import com.diffplug.gradle.spotless.SpotlessExtension
import com.diffplug.gradle.spotless.SpotlessPlugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure

val kotlinLicenseHeader = """/*
 * Copyright © 2014-2019 The Android Password Store Authors. All Rights Reserved.
 * SPDX-License-Identifier: GPL-2.0
 */
""".trimIndent()

fun Project.configureSpotless() {
    apply<SpotlessPlugin>()

    configure<SpotlessExtension> {
        java {
            target("**/src/main/**/*.java")
            trimTrailingWhitespace()
            @Suppress("INACCESSIBLE_TYPE")
            licenseHeader(kotlinLicenseHeader)
            removeUnusedImports()
            googleJavaFormat().aosp()
            endWithNewline()
        }

        kotlinGradle {
            target("*.gradle.kts", "gradle/*.gradle.kts", "buildSrc/*.gradle.kts")
            ktlint("0.31.0").userData(mapOf("indent_size" to "4", "continuation_indent_size" to "4"))
            @Suppress("INACCESSIBLE_TYPE")
            licenseHeader(kotlinLicenseHeader, "import|tasks|apply|plugins|include|buildscript")
            trimTrailingWhitespace()
            indentWithSpaces()
            endWithNewline()
        }

        kotlin {
            target("**/src/main/**/*.kt", "buildSrc/**/*.kt")
            ktlint("0.31.0").userData(mapOf("indent_size" to "4", "continuation_indent_size" to "4"))
            @Suppress("INACCESSIBLE_TYPE")
            licenseHeader(kotlinLicenseHeader, "import|package|class|object|@file")
            trimTrailingWhitespace()
            indentWithSpaces()
            endWithNewline()
        }
    }
}