Kay Werndli
01/22/2025, 1:28 PMconfigurations.all {
resolutionStrategy.cacheDynamicVersionsFor(0, "minutes")
}
(or something to that extent), but that would then be applied to all dependencies, which seems like overkill. Going through the code of the cacheDynamicVersionsFor
method, I came up with the following:
configurations.all {
val cacheAction = Action<DependencyResolutionControl> {
if(!this.cachedResult.isNullOrEmpty()) {
if(this.request.group == "our.internal.group") {
this.cacheFor(0, TimeUnit.MINUTES);
} else {
this.cacheFor(1, TimeUnit.DAYS);
}
}
}
resolutionStrategy {
if(this is DefaultResolutionStrategy) {
this.cachePolicy::class
.declaredMemberFunctions
.firstOrNull { it.name == "eachDependency" }
?.apply { isAccessible = true }
?.call(this.cachePolicy, cacheAction)
}
}
}
This seems to work but is rather ugly (obviously). It relies on manual class casting and reflection (because DefaultResolutionStrategy.eachDependency
is private). Is there a better way to do this?Vampire
01/22/2025, 1:55 PM--refresh-dependencies
once you wonder it does not use the latest version.Kay Werndli
01/22/2025, 1:56 PM--refresh-dependencies
, but it seems like a nicer experience to have the build tool take care of it.Kay Werndli
01/27/2025, 4:10 PMVampire
01/27/2025, 5:40 PMKay Werndli
01/27/2025, 5:43 PM