Consider the following buildscript where
addToMyConfig
adds a dependency to a Configuration named myConfig
useMyConfig
consumes the myConfig
Configuration and forces it to resolve()
configurations {
myConfig
}
task addToMyConfig {
doLast {
println "Doing some work"
dependencies {
myConfig 'log4j:log4j:1.2.17'
}
}
}
task useMyConfig {
doLast {
println "myConfig = $configurations.myConfig.files"
}
}
Question: Is there a way to fire addToMyConfig
every time configurations.myConfig
is resolved without adding a task dependency where useMyConfig
depends on addToMyConfig
?
I would like to say:
configurations.myConfig.builtBy addToMyConfig
** I do NOT want to say **
useMyConfig.dependsOn addToMyConfig
I want to avoid useMyConfig.dependsOn addToMyConfig
because there may be many tasks which consume configurations.myConfig
Note: There is a ConfigurableFileCollection.builtBy(Object... tasks) method which would solve my problem, if only it existed on the Configuration interface (configuration extends FileCollection)
Do you really need a task
to populate the configuration
with dependencies?
Configuration#withDependencies
can be used to add dependencies during resolution. Like this:
configurations {
myConfig
}
configurations.myConfig.withDependencies {deps ->
println "Resolving dependencies"
dependencies {
myConfig "log4j:log4j:1.2.17"
}
}
task useMyConfig {
doLast {
println "myConfig = $configurations.myConfig.files"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With