Dependency Substitution based on task

I’ve got a multi-project build and would like to be able to use dependency substitution based on which task is being executed

e.g. if I run ‘gradle mysubproject:build’ then it would build normally, if I run ‘gradle mysubproject:myspecialbuild’ then it would perform a dependency substitution.

The problem is that as far as I know, dependency substitution is run at configuration time, so you can’t change it within a task - Is that correct?

I’ve also considered having a separate configuration - the standard compile etc. WITHOUT dependency substitution and a custom one extending from compile WITH dependency substitution. The issue then is that you can’t just call build on the custom configuration and expect it to work…I think?

So, are my assumptions correct, and can you see any way of making this work?

You can use Gradle [StartParameter] (https://docs.gradle.org/current/dsl/org.gradle.api.invocation.Gradle.html#org.gradle.api.invocation.Gradle:startParameter) to find at configuration time what tasks you want to run.
Or you can base your decision on a Gradle parameter (e.g. - PuseSubstitute=true), instead of a different task. You would then use this parameter at configuration time to build your dependency substitution (or not). This second solution looks a little cleaner to me.

I was trying to avoid using a parameter since I want to keep it as simple as possible for the end users…but then again, changing the dependencies based on task is a point of confusion too.

Thanks!