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