Skip to content

Commit

Permalink
Improve consumeGeneratedConfig (detekt#6374)
Browse files Browse the repository at this point in the history
* Use TaskProvider instead of task name

* Remove redundant apply
  • Loading branch information
BraisGabin authored and mgroth0 committed Feb 11, 2024
1 parent db886fb commit 27afc34
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
13 changes: 9 additions & 4 deletions build-logic/src/main/kotlin/ConsumeGeneratedConfig.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.dependencies

fun Project.consumeGeneratedConfig(fromProject: ProjectDependency, fromConfiguration: String, forTask: String) {
val configurationName = "generatedConfigFor${forTask.replaceFirstChar { it.titlecase() }}"
val generatedConfig = configurations.create(configurationName).apply {
fun Project.consumeGeneratedConfig(
fromProject: ProjectDependency,
fromConfiguration: String,
forTask: TaskProvider<*>,
) {
val configurationName = "generatedConfigFor${forTask.name.replaceFirstChar { it.titlecase() }}"
val generatedConfig = configurations.create(configurationName) {
isCanBeConsumed = false
isCanBeResolved = true
}
Expand All @@ -16,7 +21,7 @@ fun Project.consumeGeneratedConfig(fromProject: ProjectDependency, fromConfigura
}
}

tasks.named(forTask).configure {
forTask.configure {
inputs.files(generatedConfig)
.withPropertyName(generatedConfig.name)
.withPathSensitivity(PathSensitivity.RELATIVE)
Expand Down
2 changes: 1 addition & 1 deletion detekt-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ dependencies {
consumeGeneratedConfig(
fromProject = projects.detektGenerator,
fromConfiguration = "generatedCoreConfig",
forTask = "sourcesJar"
forTask = tasks.sourcesJar
)
4 changes: 2 additions & 2 deletions detekt-formatting/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ dependencies {
consumeGeneratedConfig(
fromProject = projects.detektGenerator,
fromConfiguration = "generatedFormattingConfig",
forTask = "sourcesJar"
forTask = tasks.sourcesJar
)
consumeGeneratedConfig(
fromProject = projects.detektGenerator,
fromConfiguration = "generatedFormattingConfig",
forTask = "processResources"
forTask = tasks.processResources
)

val depsToPackage = setOf(
Expand Down
2 changes: 1 addition & 1 deletion detekt-rules-libraries/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ dependencies {
consumeGeneratedConfig(
fromProject = projects.detektGenerator,
fromConfiguration = "generatedLibrariesConfig",
forTask = "processResources"
forTask = tasks.processResources
)
2 changes: 1 addition & 1 deletion detekt-rules-ruleauthors/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies {
consumeGeneratedConfig(
fromProject = projects.detektGenerator,
fromConfiguration = "generatedRuleauthorsConfig",
forTask = "processResources"
forTask = tasks.processResources
)

kotlin {
Expand Down

0 comments on commit 27afc34

Please sign in to comment.