From f1f59dc1ed26c2351dc31e55902ff8e4b5a6ed0e Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 2 Oct 2019 18:04:18 +0530 Subject: Add Spotless to regulate codestyle (#550) * Add Spotless to regulate codestyle * treewide: Run spotless * Add spotlessCheck to CI test Signed-off-by: Harsh Shandilya --- buildSrc/build.gradle.kts | 16 ++++++++ buildSrc/src/main/kotlin/SpotlessConfiguration.kt | 47 +++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/SpotlessConfiguration.kt (limited to 'buildSrc') diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 00000000..8c3ae64d --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,16 @@ +plugins { + `kotlin-dsl` +} + +repositories { + maven("https://plugins.gradle.org/m2/") + jcenter() +} + +kotlinDslPluginOptions { + experimentalWarning.set(false) +} + +dependencies { + implementation("com.diffplug.spotless:spotless-plugin-gradle:3.24.3") +} diff --git a/buildSrc/src/main/kotlin/SpotlessConfiguration.kt b/buildSrc/src/main/kotlin/SpotlessConfiguration.kt new file mode 100644 index 00000000..3c183c5f --- /dev/null +++ b/buildSrc/src/main/kotlin/SpotlessConfiguration.kt @@ -0,0 +1,47 @@ +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() + + configure { + 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") + 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) + trimTrailingWhitespace() + indentWithSpaces() + endWithNewline() + } + } +} -- cgit v1.2.3