:wave: I have a conventional plugin sitting in inc...
# community-support
r
👋 I have a conventional plugin sitting in included-build and applied in the project. Currently, during the CC phase of the build it checks which task was used to run the build and then prints some advice on console.
Example a
clean
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.
Any ideas on how to make is always run irrespective of CC entry?
v
EIther don't do the work in configuration phase, but in execution phase, or maybe make your code inside a `ValueSource`that you evaluate at configuration time, then it will always be executed, but if CC entry is not reused then twice so you probably also have some deduplication then.
r
Thanks, looking at
ValueSource
. 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..
Is there a way to avoid
deduplication
?
The
ValueSource
gives me what i need, having the print statement inside
obtain()
, but limits me to injected any thing else other Exec** service.
v
Is 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?
r
Copy code
// 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?
v
Ah, I don't know which services are supported and which are not, this unfortunately is not clearly documented, neither which services exist, nor which can be injected where, you just have to TIAS or complain if you miss some at some point that you think might make sense.
Btw. with
Unit
you must at least be on Gradle 8.6 or CC is never reused.
r
Sure, yea i am on 8.13
Thanks - i believe
ValueSource
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()
v
Also remember, if one does
gw clea
your check will not be effective
r
Yeah, i realised while testing, abbreviations won't be valid here. Any idea on how to get it handled, I def need to look, but it's something i can live with it atm
v
You either have to do your own matching, in that case basically checking for
c
,
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-reuse
r
Yea sure, thanks
👌 1