summaryrefslogtreecommitdiff
path: root/gradle/init.gradle.kts
diff options
context:
space:
mode:
Diffstat (limited to 'gradle/init.gradle.kts')
-rw-r--r--gradle/init.gradle.kts58
1 files changed, 58 insertions, 0 deletions
diff --git a/gradle/init.gradle.kts b/gradle/init.gradle.kts
new file mode 100644
index 0000000..38989df
--- /dev/null
+++ b/gradle/init.gradle.kts
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+val ktlintVersion = "1.0.0"
+
+initscript {
+ val spotlessVersion = "6.22.0"
+
+ repositories {
+ mavenCentral()
+ }
+
+ dependencies {
+ classpath("com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion")
+ }
+}
+
+rootProject {
+ subprojects {
+ apply<com.diffplug.gradle.spotless.SpotlessPlugin>()
+ extensions.configure<com.diffplug.gradle.spotless.SpotlessExtension> {
+ // limit format enforcement to just the files changed by this feature branch
+ ratchetFrom("origin/main")
+ kotlin {
+ target("**/*.kt")
+ targetExclude("**/build/**/*.kt")
+ ktlint(ktlintVersion)
+ .setEditorConfigPath(rootProject.file(".editorconfig"))
+ licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
+ }
+ format("kts") {
+ target("**/*.kts")
+ targetExclude("**/build/**/*.kts")
+ // Look for the first line that doesn't have a block comment (assumed to be the license)
+ licenseHeaderFile(rootProject.file("spotless/copyright.kts"), "(^(?![\\/ ]\\*).*$)")
+ }
+ format("xml") {
+ target("**/*.xml")
+ targetExclude("**/build/**/*.xml")
+ // Look for the first XML tag that isn't a comment (<!--) or the xml declaration (<?xml)
+ licenseHeaderFile(rootProject.file("spotless/copyright.xml"), "(<[^!?])")
+ }
+ }
+ }
+}