Created
October 30, 2019 12:23
-
-
Save melix/b381d596ae2280703ca53ed3fc52113f to your computer and use it in GitHub Desktop.
Dumping constraints
This file contains 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
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