1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 val ktlintVersion = "1.2.1" 18 <lambda>null19initscript { 20 val spotlessVersion = "6.25.0" 21 22 repositories { 23 mavenCentral() 24 } 25 26 dependencies { 27 classpath("com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion") 28 } 29 } 30 <lambda>null31rootProject { 32 subprojects { 33 apply<com.diffplug.gradle.spotless.SpotlessPlugin>() 34 extensions.configure<com.diffplug.gradle.spotless.SpotlessExtension> { 35 // limit format enforcement to just the files changed by this feature branch 36 ratchetFrom("origin/main") 37 kotlin { 38 target("**/*.kt") 39 targetExclude("**/build/**/*.kt") 40 ktlint(ktlintVersion) 41 .setEditorConfigPath(rootProject.file(".editorconfig")) 42 licenseHeaderFile(rootProject.file("spotless/copyright.kt")) 43 .updateYearWithLatest(false) 44 } 45 format("kts") { 46 target("**/*.kts") 47 targetExclude("**/build/**/*.kts") 48 // Look for the first line that doesn't have a block comment (assumed to be the license) 49 licenseHeaderFile(rootProject.file("spotless/copyright.kts"), "(^(?![\\/ ]\\*).*$)") 50 .updateYearWithLatest(false) 51 } 52 format("xml") { 53 target("**/*.xml") 54 targetExclude("**/build/**/*.xml") 55 // Look for the first XML tag that isn't a comment (<!--) or the xml declaration (<?xml) 56 licenseHeaderFile(rootProject.file("spotless/copyright.xml"), "(<[^!?])") 57 .updateYearWithLatest(false) 58 } 59 } 60 } 61 } 62