Skip to content

Instantly share code, notes, and snippets.

@melix
Created October 30, 2019 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melix/b381d596ae2280703ca53ed3fc52113f to your computer and use it in GitHub Desktop.
Save melix/b381d596ae2280703ca53ed3fc52113f to your computer and use it in GitHub Desktop.
Dumping constraints
import javax.inject.Inject
plugins {
id 'java-library'
}
repositories {
mavenCentral()
}
configurations {
declaredConstraints
}
def provider = layout.buildDirectory.file("constraints.txt")
dependencies {
declaredConstraints platform('org.springframework.boot:spring-boot-dependencies:2.1.9.RELEASE')
components.all(ExtractConstraintsFromPlatform) {
params(provider)
}
}
task showConstraints {
doLast {
configurations.declaredConstraints.resolve()
println provider.get().asFile.text
}
}
class ExtractConstraintsFromPlatform implements ComponentMetadataRule {
private final Provider<RegularFile> outputFile
@Inject
ExtractConstraintsFromPlatform(Provider<RegularFile> out) {
outputFile = out
}
void execute(ComponentMetadataContext context) {
Set<String> declared = []
def out = outputFile.get().asFile
out.parentFile.mkdirs()
out.delete()
context.details.allVariants {
withDependencyConstraints {
out.withWriterAppend { writer ->
it.each {
if (declared.add(it)) {
writer.println(it)
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment