Created
March 11, 2022 17:07
-
-
Save ghale/6122c530859cb23c616d8c5899e262c2 to your computer and use it in GitHub Desktop.
Capture dynamic version TTL for all configurations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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