Skip to content

Commit 0726d0f

Browse files
committed
build(Gradle): Make task configuration compatible with the cache
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]>
1 parent d28c387 commit 0726d0f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

detekt-rules/build.gradle.kts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import org.gradle.internal.logging.text.StyledTextOutput
2121
import org.gradle.internal.logging.text.StyledTextOutputFactory
22-
import org.gradle.kotlin.dsl.support.serviceOf
2322

2423
plugins {
2524
// Apply precompiled plugins.
@@ -41,9 +40,18 @@ configurations.all {
4140
}
4241
}
4342

43+
// A provider to get a StyledTextOutputFactory via dependency injection.
44+
interface StyledTextOutputProvider {
45+
@get:Inject
46+
val out: StyledTextOutputFactory
47+
}
48+
4449
tasks.named<Jar>("jar") {
50+
// Resolve objects at configuration time to be compatible with the configuration cache.
51+
val objects = objects
52+
4553
doLast {
46-
val out = serviceOf<StyledTextOutputFactory>().create("detekt-rules")
54+
val out = objects.newInstance<StyledTextOutputProvider>().out.create("detekt-rules")
4755
val message = "The detekt-rules have changed. You need to stop the Gradle daemon to allow the detekt plugin " +
4856
"to reload for the rule changes to take effect."
4957
out.withStyle(StyledTextOutput.Style.Info).println(message)

0 commit comments

Comments
 (0)