Skip to content

Instantly share code, notes, and snippets.

@kkonyshev
Last active September 5, 2017 08:46
Show Gist options
  • Save kkonyshev/f6996fa27497dcbb8e4cfd88832ec9be to your computer and use it in GitHub Desktop.
Save kkonyshev/f6996fa27497dcbb8e4cfd88832ec9be to your computer and use it in GitHub Desktop.
dependency conflicts spotting
1) preapre raw dependencies
./dependency-list.sh ipflow-parent.pom
./dependency-list.sh link-core-1.3.2.pom
2) compile
javac ConfiltList.java
3) execute
java ConfiltList ipflow-parent.pom.dep.raw flink-core-1.3.2.pom.dep.raw
4) file: dependency-list.sh
#!/bin/sh
POMFILE=$1
#wget http://central.maven.org/maven2/org/apache/flink/flink-core/1.3.2/flink-core-1.3.2.pom
mvn dependency:tree -f $POMFILE > $POMFILE.dep
cat $POMFILE.dep | grep '[INFO]' | awk 'match($0, /\:jar\:.*/) && $0!~"test" {print $0}' | awk -F "- " '{print $2 ":flink-core-1.3.2"}' | sort | uniq > $POMFILE.dep.raw
5) file: ConfiltList.java
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
/**
* Created by Konstantin Konyshev on 05/09/2017.
*/
public class ConfiltList {
public static void main (String[] argv) throws IOException {
String baseFile = argv[0];
String extFile = argv[1];
Map<String, TreeMap<String, String>> verMap = new HashMap<>();
for (String file: argv) {
System.out.println("Processing: " + file);
Path path = Paths.get(file);
if (Files.isRegularFile(path)) {
Files.readAllLines(path, Charset.defaultCharset()).stream()
.forEach(line -> {
String[] split = line.split(":");
if (split.length==6) {
String group = split[0];
String art = split[1];
String ver = split[3];
String env = split[4];
if (verMap.get(file) == null) {
verMap.put(file, new TreeMap<>());
}
verMap.get(file).put(group + ":" + art + ":" + env, ver);
}
}
);
}
}
TreeMap<String, String> baseFileMap = verMap.get(baseFile);
TreeMap<String, String> extFileMap = verMap.get(extFile);
baseFileMap.entrySet().stream()
.filter(appMap ->
extFileMap.containsKey(appMap.getKey()) && !extFileMap.get(appMap.getKey()).equals(appMap.getValue()))
.forEach(appMap ->
System.out.println("Dependency conflict (" + baseFile + "->" + extFile +"): " + appMap.getKey()
+ ": " + baseFileMap.get(appMap.getKey()) + "->" + extFileMap.get(appMap.getKey()))
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment