/** * Given a local path to a Maven project, this attempts to find the transitive dependencies of the * project. * * @param projectPath The path to search for Maven projects. * @param scopes The scopes to look up dependencies in. */ public String resolvePomDependencies(String projectPath, Set<String> scopes) { DefaultModelProcessor processor = new DefaultModelProcessor(); processor.setModelLocator(new DefaultModelLocator()); processor.setModelReader(new DefaultModelReader()); File pom = processor.locatePom(new File(projectPath)); FileModelSource pomSource = new FileModelSource(pom); // First resolve the model source locations. resolveSourceLocations(pomSource); // Next, fully resolve the models. Model model = modelResolver.getEffectiveModel(pomSource); if (model != null) { traverseDeps(model, scopes, Sets.newHashSet(), null); } return pom.getAbsolutePath(); }
private static Model readModel() { DefaultModelProcessor modelProcessor = new DefaultModelProcessor(); modelProcessor.setModelLocator(new DefaultModelLocator()); modelProcessor.setModelReader(new DefaultModelReader()); try { return modelProcessor.read(SpringBootDependenciesDependencyManagement.class .getResourceAsStream("effective-pom.xml"), null); } catch (IOException ex) { throw new IllegalStateException("Failed to build model from effective pom", ex); } }