public List<String> extractClasspathEntries(File pomFile, String scope) throws MavenClasspathExtractionException { try { MavenRequest mavenRequest = mavenConfiguration(); mavenRequest.setResolveDependencies(true); mavenRequest.setBaseDirectory(pomFile.getParent()); mavenRequest.setPom(pomFile.getAbsolutePath()); DependencyResolvingMavenEmbedder dependencyResolvingMavenEmbedder = new DependencyResolvingMavenEmbedder(getClass().getClassLoader(), mavenRequest); ProjectBuildingResult projectBuildingResult = dependencyResolvingMavenEmbedder.buildProject(pomFile); return getClasspathForScope(projectBuildingResult, scope); } catch (MavenEmbedderException mee) { throw new MavenClasspathExtractionException(mee); } catch (ComponentLookupException cle) { throw new MavenClasspathExtractionException(cle); } catch (DependencyResolutionRequiredException e) { throw new MavenClasspathExtractionException(e); } catch (ProjectBuildingException e) { throw new MavenClasspathExtractionException(e); } }
// protected for test purposes protected MavenRequest mavenConfiguration() throws MavenEmbedderException, ComponentLookupException { MavenRequest mavenRequest = new MavenRequest(); if (userSettingsFile != null && userSettingsFile.exists()) { mavenRequest.setUserSettingsFile(userSettingsFile.getAbsolutePath()); } if (globalSettingsFile != null && globalSettingsFile.exists()) { mavenRequest.setGlobalSettingsFile(globalSettingsFile.getAbsolutePath()); } DependencyResolvingMavenEmbedder mavenEmbedder = new DependencyResolvingMavenEmbedder( MavenClasspathExtractor.class.getClassLoader(), mavenRequest); mavenEmbedder .getMavenRequest() .setLocalRepositoryPath( getLocalRepository(mavenEmbedder.getSettings().getLocalRepository())); return mavenEmbedder.getMavenRequest(); }