Skip to content

Instantly share code, notes, and snippets.

@ghale
Created March 11, 2022 17:07
Show Gist options
  • Save ghale/6122c530859cb23c616d8c5899e262c2 to your computer and use it in GitHub Desktop.
Save ghale/6122c530859cb23c616d8c5899e262c2 to your computer and use it in GitHub Desktop.
Capture dynamic version TTL for all configurations
allprojects { p ->
rootProject.buildScan.buildFinished {
def field = getAccessibleField(org.gradle.api.internal.artifacts.ivyservice.resolutionstrategy.DefaultCachePolicy, "keepDynamicVersionsFor")
p.configurations.each { config ->
rootProject.buildScan.value "${p.name}.${config.name}.keepDynamicVersionsFor", "${field.get(config.resolutionStrategy.cachePolicy)/1000}s"
}
}
}
def getAccessibleField(Class<?> clazz, String fieldName) {
for (java.lang.reflect.Field field : clazz.declaredFields) {
if (field.name == fieldName) {
field.setAccessible(true)
return field
}
}
if (clazz.superclass != null) {
return getAccessibleField(clazz.superclass, fieldName)
} else {
throw new RuntimeException("Field '${fieldName}' not found")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment