ExternalLibraryDependency (File file, File modules2Dir, String scope) { File sourcesFile = null; try { String modules2Path = modules2Dir.getCanonicalPath(); String filePath = file.getCanonicalPath(); if (filePath.startsWith(modules2Path)) { List<File> parents = new ArrayList<>(); File parent = file.getParentFile(); while(parent != null && !parent.getName().equals(modules2Dir.getName())) { parents.add(parent); parent = parent.getParentFile(); } File groupDir = parents.get(parents.size() - 1); File artifactDir = parents.get(parents.size() - 2); File versionDir = parents.get(parents.size() - 3); if (versionDir != null) { File[] hashDirs = versionDir.listFiles(); if (hashDirs != null) { for (File hashDir : hashDirs) { File[] sourcesJars = hashDir.listFiles((dir, name) -> name.endsWith("sources.jar")); if (sourcesJars != null && sourcesJars.length > 0) { sourcesFile = sourcesJars[0]; break; } } String packaging = resolvePackagingType(file); String classifier = resolveClassifier(artifactDir.getName(), versionDir.getName(), file); DefaultExternalLibraryDependency defaultDependency = new DefaultExternalLibraryDependency(); defaultDependency.setName(artifactDir.getName()); defaultDependency.setGroup(groupDir.getName()); defaultDependency.setPackaging(packaging); defaultDependency.setClassifier(classifier); defaultDependency.setVersion(versionDir.getName()); defaultDependency.setFile(file); defaultDependency.setSource(sourcesFile); defaultDependency.setScope(scope); return defaultDependency; } } } } catch (IOException e) { throw new RuntimeException(e); } return null; }