Hey! I have a somewhat specific question about con...
# community-support
k
Hey! I have a somewhat specific question about configuring Gradle's dependency cache. I did find a solution but it's hacky and I wanted to double-check if there's a proper way to achieve this. Gradle's default TTL for dynamic versions is 24 hours, which is fine for external dependencies but not internal ones. We had a few people run into this and being confused why their build wouldn't pull in a recently updated version of our own tools. From what I can tell reading the docs, the obvious solution is to add
Copy code
configurations.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:
Copy code
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?
v
Doesn't mean much, but I'm not aware of a public way to configure the TTL for specific dynamic versions. Maybe you should open a feature request if there is none yet. A manual way would be to use
--refresh-dependencies
once you wonder it does not use the latest version.
k
Indeed, we considered just telling people to use
--refresh-dependencies
, but it seems like a nicer experience to have the build tool take care of it.
1
I finally got around to opening a feature request for this. Thank you very much for your time and suggestions!
v
Would probably make sense to post it here too for future readers stumbling over this thread. 😉
k