- Upgrades to spotless 8.2.1 - Moves spotless setup from an init.gradle.kts to build-logic - Narrows down the scope of `target` in spotless configuration to be more precise to workaround https://github.com/diffplug/spotless/issues/2717 - Updates all references to init.gradle.kts Ran gradle-profiler ./gradlew build --dry-run to validate performance impact. Before PR: Mean 10,527.96 ms with 289.01 ms std dev After PR: Mean 11,251.78 ms with 530.29 ms std dev Regression is there, but quite minor. Test: ./gradlew spotlessCheckpull/2055/head
parent
eee94e4b7d
commit
dacf13ca7f
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2026 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
|
||||
*
|
||||
* https://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.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid
|
||||
|
||||
import com.diffplug.gradle.spotless.SpotlessExtension
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
|
||||
internal fun Project.configureSpotlessForAndroid() {
|
||||
configureSpotlessCommon()
|
||||
extensions.configure<SpotlessExtension> {
|
||||
format("xml") {
|
||||
target("src/**/*.xml")
|
||||
// Look for the first XML tag that isn't a comment (<!--) or the xml declaration (<?xml)
|
||||
licenseHeaderFile(rootProject.file("spotless/copyright.xml"), "(<[^!?])")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Project.configureSpotlessForJvm() {
|
||||
configureSpotlessCommon()
|
||||
}
|
||||
|
||||
private fun Project.configureSpotlessCommon() {
|
||||
apply(plugin = "com.diffplug.spotless")
|
||||
extensions.configure<SpotlessExtension> {
|
||||
kotlin {
|
||||
target("src/**/*.kt")
|
||||
ktlint(libs.findVersion("ktlint").get().requiredVersion).editorConfigOverride(
|
||||
mapOf("android" to "true")
|
||||
)
|
||||
licenseHeaderFile(rootDir.resolve("spotless/copyright.kt"))
|
||||
}
|
||||
format("kts") {
|
||||
target("*.kts")
|
||||
// Look for the first line that doesn't have a block comment (assumed to be the license)
|
||||
licenseHeaderFile(rootDir.resolve("spotless/copyright.kts"), "(^(?![\\/ ]\\*).*$)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022 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
|
||||
*
|
||||
* https://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.4.0"
|
||||
|
||||
initscript {
|
||||
val spotlessVersion = "6.25.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> {
|
||||
kotlin {
|
||||
target("**/*.kt")
|
||||
targetExclude("**/build/**/*.kt")
|
||||
ktlint(ktlintVersion).editorConfigOverride(
|
||||
mapOf(
|
||||
"android" to "true",
|
||||
),
|
||||
)
|
||||
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"), "(<[^!?])")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue