Configuration to have task dependency (builtBy)

I’d like to do some “work” in a task which adds dependencies to a configuration. I therefore want the task to run every time the configuration is resolved

Consider the following:

configurations {
	myConfig
}
task addToMyConfig {
	doLast {
		println "Doing some work"
		dependencies {
			myConfig 'log4j:log4j:1.2.17'
		}
	}
}
task useMyConfig {
	doLast {
		println "myConfig = $configurations.myConfig.files"
	}
}

How do I force addToMyConfig to run every time myConfig is resolved? Eg useMyConfig should ultimately depend on addToMyConfig

** Note ** I do not want to explicitly do

useMyConfig.dependsOn addToMyConfig

Because I don’t know all the tasks which use myConfig. I’d like something like

configurations.myConfig.builtBy addToMyConfig

Just bumping this issue. I note that ConfigurableFileCollection has a builtBy(Object… tasks) method. If this could be added to Configuration also it would solve the problem

I’ve created a bounty for this question on stack overflow, any suggestions appreciated