i try to set some dependency constraints in a plugin. The following code does not work. On which configuration do i have to add the constraints and how to force a download of the new constraints?
public void apply(Project project) {
Logger logger = project.getLogger();
project.getConfigurations().all(configuration -> {
if (!configuration.getDependencies().isEmpty()) { //which configuration should be used??
final DependencyHandler dependencyHandler = project.getDependencies();
dependencyHandler.constraints(
constraintHandler -> {
final DependencyConstraint dependencyConstraint = constraintHandler.create("org.yaml:snakeyaml:2.0");
dependencyConstraint.because("test");
if (dependencyConstraint instanceof DependencyConstraintInternal) {
((DependencyConstraintInternal) dependencyConstraint).setForce(true);
logger.warn("Forced constraint {}", dependencyConstraint.getName());
} else {
logger.warn("Unable to force constraint {}", dependencyConstraint.getName());
}
configuration.getDependencyConstraints().add(dependencyConstraint);
}
);
}
});