Skip to content

Commit

Permalink
build(Gradle): Make task configuration compatible with the cache
Browse files Browse the repository at this point in the history
Make the configuration refinement of the "jar" task compatible with
Gradle's new configuration cache [1] by getting `StyledTextOutputFactory`
via dependency injection.

[1]: https://docs.gradle.org/current/userguide/configuration_cache.html

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Jul 4, 2023
1 parent d28c387 commit 0726d0f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions detekt-rules/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.gradle.internal.logging.text.StyledTextOutput
import org.gradle.internal.logging.text.StyledTextOutputFactory
import org.gradle.kotlin.dsl.support.serviceOf

plugins {
// Apply precompiled plugins.
Expand All @@ -41,9 +40,18 @@ configurations.all {
}
}

// A provider to get a StyledTextOutputFactory via dependency injection.
interface StyledTextOutputProvider {
@get:Inject
val out: StyledTextOutputFactory
}

tasks.named<Jar>("jar") {
// Resolve objects at configuration time to be compatible with the configuration cache.
val objects = objects

doLast {
val out = serviceOf<StyledTextOutputFactory>().create("detekt-rules")
val out = objects.newInstance<StyledTextOutputProvider>().out.create("detekt-rules")
val message = "The detekt-rules have changed. You need to stop the Gradle daemon to allow the detekt plugin " +
"to reload for the rule changes to take effect."
out.withStyle(StyledTextOutput.Style.Info).println(message)
Expand Down

0 comments on commit 0726d0f

Please sign in to comment.