mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-11-08 11:13:00 +00:00
Relocate toml lint task to buildSrc and extend against default task
Fixes build errors after Gradle 9.x upgrade Ref: https://docs.gradle.org/current/userguide/implementing_custom_tasks.html Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -12,8 +12,6 @@ plugins {
|
||||
checkstyle
|
||||
}
|
||||
|
||||
apply(from = "check-dependencies.gradle.kts")
|
||||
|
||||
val gitWorkingBranch = providers.exec {
|
||||
commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||
}.standardOutput.asText.map { it.trim() }
|
||||
@@ -172,6 +170,10 @@ tasks.register<JavaExec>("formatKtlint") {
|
||||
jvmArgs = listOf("--add-opens", "java.base/java.lang=ALL-UNNAMED")
|
||||
}
|
||||
|
||||
tasks.register<CheckDependenciesOrder>("checkDependenciesOrder") {
|
||||
tomlFile = layout.projectDirectory.file("../gradle/libs.versions.toml")
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
tasks.named("preDebugBuild").configure {
|
||||
if (!System.getProperties().containsKey("skipFormatKtlint")) {
|
||||
|
||||
7
buildSrc/build.gradle.kts
Normal file
7
buildSrc/build.gradle.kts
Normal file
@@ -0,0 +1,7 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
@@ -4,18 +4,27 @@
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
tasks.register("checkDependenciesOrder") {
|
||||
group = "verification"
|
||||
description = "Checks that each section in libs.versions.toml is sorted alphabetically"
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
val tomlFile = file("../gradle/libs.versions.toml")
|
||||
abstract class CheckDependenciesOrder : DefaultTask() {
|
||||
|
||||
doLast {
|
||||
if (!tomlFile.exists()) {
|
||||
throw GradleException("TOML file not found")
|
||||
}
|
||||
@get:InputFile
|
||||
abstract val tomlFile: RegularFileProperty
|
||||
|
||||
val lines = tomlFile.readLines()
|
||||
init {
|
||||
group = "verification"
|
||||
description = "Checks that each section in libs.versions.toml is sorted alphabetically"
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val file = tomlFile.get().asFile
|
||||
if (!file.exists()) error("TOML file not found")
|
||||
|
||||
val lines = file.readLines()
|
||||
val nonSortedBlocks = mutableListOf<List<String>>()
|
||||
var currentBlock = mutableListOf<String>()
|
||||
var prevLine = ""
|
||||
@@ -50,7 +59,7 @@ tasks.register("checkDependenciesOrder") {
|
||||
}
|
||||
|
||||
if (nonSortedBlocks.isNotEmpty()) {
|
||||
throw GradleException(
|
||||
error(
|
||||
"The following lines were not sorted:\n" +
|
||||
nonSortedBlocks.joinToString("\n\n") { it.joinToString("\n") }
|
||||
)
|
||||
Reference in New Issue
Block a user