ritesh singh
03/04/2025, 2:46 AMritesh singh
03/04/2025, 2:48 AMclean
task - ./gradlew clean
With config cache enabled in my project, my conventional plugin works at first attempt but not when CC entry is re-used, which is an expected behavour.ritesh singh
03/04/2025, 2:48 AMVampire
03/04/2025, 2:55 AMritesh singh
03/04/2025, 2:59 AMValueSource
. I want to do the work at early as possible, cannot defer it to later phase.
In this case for few things like
• print advice via various means when clean task is invoked on root-level of project
• some must env variable required to run the build like matching jvm version, develocity access key etc..
• etc..ritesh singh
03/04/2025, 3:04 AMdeduplication
?ritesh singh
03/04/2025, 7:26 AMValueSource
gives me what i need, having the print statement inside obtain()
, but limits me to injected any thing else other Exec** service.Vampire
03/04/2025, 7:57 AMIs there a way to avoid deduplication ?
If you have a value source that is evaluated at configuration time, it will be evaluated twice if a CC entry exists but cannot be reused, fullstop. First to evaluate whether the CC entry can be reused, second during actually running configuration phase.
but limits me to injected any thing else other Exec** service.
I don't get what you mean, can you show your code?
ritesh singh
03/04/2025, 8:11 AM// this can't be injected or passed as an param because it cant be seralizable
abstract class ValueSource @Inject constructor(// Cannot inject Problems here) : ValueSource<Unit, ValueSourceParameters.None> {
override fun obtain() {
println("Message on console")
}
}
class MyCustomPlugin @Inject constructor(private val problems: Problems) : Plugin<Project> {
override fun apply(project: Project) = project.run {
when {
!isCIBuild && gradle.startParameter.taskNames.contains("clean") -> providers.of(ValuSource::class.java) {}.get()
}
}
}
Something like this, with this approach, irrespective of CC, Message on console
will be printed which i verified, even if the CC is reused other scenario i need to test.
> I don't get what you mean, can you show your code?
Sure, i meant only ExecOperations service injection is supported? and cannot inject any other type like Problems or other service?Vampire
03/04/2025, 8:42 AMVampire
03/04/2025, 8:43 AMUnit
you must at least be on Gradle 8.6 or CC is never reused.ritesh singh
03/04/2025, 8:43 AMritesh singh
03/04/2025, 8:48 AMValueSource
works for me, it seems like the best option atm for my use-case, without compromising with CC re-use.
I can live with not able to pass Problem's api,
• because in MyCustomPlugin
, i can report when CC is invalid and that generates the HTML report.
• and, message i want to print on console irrespective of CC state is achievable via having it in obtain()Vampire
03/04/2025, 8:52 AMgw clea
your check will not be effectiveritesh singh
03/04/2025, 8:53 AMVampire
03/04/2025, 9:57 AMc
, cl
, cle
, clea
, and clean
I think.
Or you have to instead check in the task graph, but I don't think you can there do it always even on CC-reuseritesh singh
03/04/2025, 12:35 PM