static void validateDependencies(Set<Artifact> dependencies, Set<String> allowedRules, boolean failOnUnmatched)
            throws EnforcerRuleException {
        SortedSet<Artifact> unmatchedArtifacts = new TreeSet<>();
        Set<String> matchedRules = new HashSet<>();
        for (Artifact dependency : dependencies) {
            boolean matches = false;
            for (String rule : allowedRules) {
                if (matches(dependency, rule)){
                    matchedRules.add(rule);
                    matches = true;
                    break;
                }
            }
            if (!matches) {
                unmatchedArtifacts.add(dependency);
            }
        }
        SortedSet<String> unmatchedRules = new TreeSet<>(allowedRules);
        unmatchedRules.removeAll(matchedRules);
        if (!unmatchedArtifacts.isEmpty() || (failOnUnmatched && !unmatchedRules.isEmpty())) {
            StringBuilder errorMessage = new StringBuilder("Vespa dependency enforcer failed:\n");
            if (!unmatchedArtifacts.isEmpty()) {
                errorMessage.append("Dependencies not matching any rule:\n");
                unmatchedArtifacts.forEach(a -> errorMessage.append(" - ").append(a.toString()).append('\n'));
            }
            if (failOnUnmatched && !unmatchedRules.isEmpty()) {
                errorMessage.append("Rules not matching any dependency:\n");
                unmatchedRules.forEach(p -> errorMessage.append(" - ").append(p).append('\n'));
            }
            throw new EnforcerRuleException(errorMessage.toString());
        }
    }
Enforces that all expected dependencies are present.
Fails by default for rules that do not match any dependencies.
Similar to the built-in 'bannedDependencies' rule in maven-enforcer-plugin.

@author bjorncs
vespa-enforcer-extensions/src/main/java/com/yahoo/vespa/maven/plugin/enforcer/EnforceDependencies.java