@Test public void resolveAlreadyResolvedNotReturned() throws Exception { IvyDependencyResolver resolver = new IvyDependencyResolver(); List<Dependency> dependencies = Arrays.asList( Dependency.parse("commons-io:commons-io:2.5")); List<File> files = resolver.resolve(context, dependencies, dependencies); assertThat(files, hasSize(0)); }
@Override public List<File> resolve( Context context, List<Dependency> resolvedDependencies, List<Dependency> dependencies) throws DependencyResolveException, ParseException, IOException { Objects.requireNonNull(context, "context may not be null"); Objects.requireNonNull(resolvedDependencies, "resolvedDependencies may not be null"); Objects.requireNonNull(dependencies, "dependencies may not be null"); log.trace("Already resolved dependencies {}", resolvedDependencies); log.trace("Dependencies to resolve {}", dependencies); Message.setDefaultLogger(new FilteringIvyLogger()); MavenSettings mavenSettings = null; Path mavenSettingsFile = context.userDir().resolve(".m2/settings.xml"); if (Files.exists(mavenSettingsFile)) { try { mavenSettings = MavenSettings.parse(mavenSettingsFile); log.debug("Using maven settings {}", mavenSettingsFile); } catch (Exception e) { log.error("Unable to cleanly parse {}", mavenSettingsFile, e); } } final IvyAuthenticator authenticator = new IvyAuthenticator(); Authenticator.setDefault(authenticator); Ivy ivy = Ivy.newInstance(); IvySettings ivySettings = ivy.getSettings(); if (context.config().value(Config.KEY_DEPENDENCY_CLEAN, Boolean.class).getOr(Config.DEFAULT_DEPENDENCY_CLEAN)) { log.info("Cleaning dependency cache..."); ivy.getResolutionCacheManager().clean(); } dependencies.stream().forEach((d) -> { if (d.getVersion().endsWith("-SNAPSHOT")) { Path cachedFile = context.userDir().resolve(".ivy2/cache/" + d.getGroupId() + "/" + d.getArtifactId() + "/jars/" + d.getArtifactId() + "-" + d.getVersion() + ".jar"); if (Files.exists(cachedFile)) { log.trace("Deleting cached snapshot dependency {}", cachedFile); try { Files.delete(cachedFile); } catch (IOException e) { log.trace("Unable to delete", e.getMessage()); } } } }); IBiblioResolver mavenCentralResolver = new IBiblioResolver(); mavenCentralResolver.setM2compatible(true); mavenCentralResolver.setName("mavenCentral"); mavenCentralResolver.setUseMavenMetadata(true); final List<IBiblioResolver> additionalResolvers = new ArrayList<>(); final List<String> repositoryUrls = context != null && context.config() != null ? context.config().valueList(Config.KEY_REPOSITORIES).orNull() : null; if (repositoryUrls != null) { for (String repositoryUrl : repositoryUrls) { MavenRepositoryUrl mru = MavenRepositoryUrl.parse(repositoryUrl); MavenServer mavenServer = ofNullable(mavenSettings) .map(v -> v.findServerById(mru.getId())) .orElse(null); log.debug("Adding extra maven repo: {}->{}", mru.getId(), mru.getUrl()); if (mavenServer != null) { String host = mru.getUrl().getHost(); log.debug("Using maven settings credentials for id={}, host={}, username={}", mru.getId(), host, mavenServer.getUsername()); authenticator.addCredentials(host, mavenServer.getUsername(), mavenServer.getPassword()); } IBiblioResolver additionalResolver = new IBiblioResolver(); additionalResolver.setM2compatible(true); additionalResolver.setName(mru.getId()); additionalResolver.setUseMavenMetadata(true); additionalResolver.setRoot(mru.getUrl().toString()); additionalResolvers.add(additionalResolver); } } FileSystemResolver mavenLocalResolver = new FileSystemResolver(); mavenLocalResolver.setName("mavenLocal"); mavenLocalResolver.setLocal(true); File userHomeDir = context.userDir().toFile(); mavenLocalResolver.addArtifactPattern(userHomeDir.getAbsolutePath() + "/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]"); mavenLocalResolver.addIvyPattern(userHomeDir.getAbsolutePath() + "/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].pom"); mavenLocalResolver.setM2compatible(true); mavenLocalResolver.setChangingMatcher(PatternMatcher.REGEXP); mavenLocalResolver.setChangingPattern(".*-SNAPSHOT"); mavenLocalResolver.setCheckmodified(true); ChainResolver chainResolver = new ChainResolver(); chainResolver.setName("default"); chainResolver.add(mavenLocalResolver); chainResolver.add(mavenCentralResolver); chainResolver.setDual(true); additionalResolvers.forEach(v -> { chainResolver.add(v); }); ivySettings.addResolver(chainResolver); ivy.getSettings().setDefaultResolver(chainResolver.getName()); DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance( ModuleRevisionId.newInstance("blaze", "blaze", "resolver")); dependencies.stream() .map((d) -> { boolean isChanging = d.getVersion().endsWith("-SNAPSHOT"); return new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(d.getGroupId(), d.getArtifactId(), d.getVersion()), false, isChanging, true); }) .forEach((dd) -> { dd.addDependencyConfiguration("default", "default"); md.addDependency(dd); }); String[] confs = new String[] { "default" }; ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs); resolveOptions.setRefresh(true); ResolveReport report = ivy.resolve(md, resolveOptions); if (report.hasError()) { String firstMessage = (String)report.getAllProblemMessages().get(0); throw new DependencyResolveException(firstMessage); } final Set<String> alreadyResolved = DependencyHelper.toGroupArtifactSet(resolvedDependencies); final Set<String> alreadyExcluded = new HashSet<>(); List<File> jarFiles = new ArrayList<>(); for (ArtifactDownloadReport adr : report.getAllArtifactsReports()) { Artifact artifact = adr.getArtifact(); String key = artifact.getModuleRevisionId().getOrganisation() + ":" + artifact.getModuleRevisionId().getName(); log.trace("Potentially filtering {} with key {}", artifact, key); if (alreadyResolved.contains(key)) { log.debug("Excluding {} (already added to classpath)", artifact); } else if (adr.getLocalFile() != null) { jarFiles.add(adr.getLocalFile()); } } return jarFiles; }
IvyDependencyResolver implements DependencyResolver { @Override public List<File> resolve( Context context, List<Dependency> resolvedDependencies, List<Dependency> dependencies) throws DependencyResolveException, ParseException, IOException { Objects.requireNonNull(context, "context may not be null"); Objects.requireNonNull(resolvedDependencies, "resolvedDependencies may not be null"); Objects.requireNonNull(dependencies, "dependencies may not be null"); log.trace("Already resolved dependencies {}", resolvedDependencies); log.trace("Dependencies to resolve {}", dependencies); Message.setDefaultLogger(new FilteringIvyLogger()); MavenSettings mavenSettings = null; Path mavenSettingsFile = context.userDir().resolve(".m2/settings.xml"); if (Files.exists(mavenSettingsFile)) { try { mavenSettings = MavenSettings.parse(mavenSettingsFile); log.debug("Using maven settings {}", mavenSettingsFile); } catch (Exception e) { log.error("Unable to cleanly parse {}", mavenSettingsFile, e); } } final IvyAuthenticator authenticator = new IvyAuthenticator(); Authenticator.setDefault(authenticator); Ivy ivy = Ivy.newInstance(); IvySettings ivySettings = ivy.getSettings(); if (context.config().value(Config.KEY_DEPENDENCY_CLEAN, Boolean.class).getOr(Config.DEFAULT_DEPENDENCY_CLEAN)) { log.info("Cleaning dependency cache..."); ivy.getResolutionCacheManager().clean(); } dependencies.stream().forEach((d) -> { if (d.getVersion().endsWith("-SNAPSHOT")) { Path cachedFile = context.userDir().resolve(".ivy2/cache/" + d.getGroupId() + "/" + d.getArtifactId() + "/jars/" + d.getArtifactId() + "-" + d.getVersion() + ".jar"); if (Files.exists(cachedFile)) { log.trace("Deleting cached snapshot dependency {}", cachedFile); try { Files.delete(cachedFile); } catch (IOException e) { log.trace("Unable to delete", e.getMessage()); } } } }); IBiblioResolver mavenCentralResolver = new IBiblioResolver(); mavenCentralResolver.setM2compatible(true); mavenCentralResolver.setName("mavenCentral"); mavenCentralResolver.setUseMavenMetadata(true); final List<IBiblioResolver> additionalResolvers = new ArrayList<>(); final List<String> repositoryUrls = context != null && context.config() != null ? context.config().valueList(Config.KEY_REPOSITORIES).orNull() : null; if (repositoryUrls != null) { for (String repositoryUrl : repositoryUrls) { MavenRepositoryUrl mru = MavenRepositoryUrl.parse(repositoryUrl); MavenServer mavenServer = ofNullable(mavenSettings) .map(v -> v.findServerById(mru.getId())) .orElse(null); log.debug("Adding extra maven repo: {}->{}", mru.getId(), mru.getUrl()); if (mavenServer != null) { String host = mru.getUrl().getHost(); log.debug("Using maven settings credentials for id={}, host={}, username={}", mru.getId(), host, mavenServer.getUsername()); authenticator.addCredentials(host, mavenServer.getUsername(), mavenServer.getPassword()); } IBiblioResolver additionalResolver = new IBiblioResolver(); additionalResolver.setM2compatible(true); additionalResolver.setName(mru.getId()); additionalResolver.setUseMavenMetadata(true); additionalResolver.setRoot(mru.getUrl().toString()); additionalResolvers.add(additionalResolver); } } FileSystemResolver mavenLocalResolver = new FileSystemResolver(); mavenLocalResolver.setName("mavenLocal"); mavenLocalResolver.setLocal(true); File userHomeDir = context.userDir().toFile(); mavenLocalResolver.addArtifactPattern(userHomeDir.getAbsolutePath() + "/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]"); mavenLocalResolver.addIvyPattern(userHomeDir.getAbsolutePath() + "/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].pom"); mavenLocalResolver.setM2compatible(true); mavenLocalResolver.setChangingMatcher(PatternMatcher.REGEXP); mavenLocalResolver.setChangingPattern(".*-SNAPSHOT"); mavenLocalResolver.setCheckmodified(true); ChainResolver chainResolver = new ChainResolver(); chainResolver.setName("default"); chainResolver.add(mavenLocalResolver); chainResolver.add(mavenCentralResolver); chainResolver.setDual(true); additionalResolvers.forEach(v -> { chainResolver.add(v); }); ivySettings.addResolver(chainResolver); ivy.getSettings().setDefaultResolver(chainResolver.getName()); DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance( ModuleRevisionId.newInstance("blaze", "blaze", "resolver")); dependencies.stream() .map((d) -> { boolean isChanging = d.getVersion().endsWith("-SNAPSHOT"); return new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(d.getGroupId(), d.getArtifactId(), d.getVersion()), false, isChanging, true); }) .forEach((dd) -> { dd.addDependencyConfiguration("default", "default"); md.addDependency(dd); }); String[] confs = new String[] { "default" }; ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs); resolveOptions.setRefresh(true); ResolveReport report = ivy.resolve(md, resolveOptions); if (report.hasError()) { String firstMessage = (String)report.getAllProblemMessages().get(0); throw new DependencyResolveException(firstMessage); } final Set<String> alreadyResolved = DependencyHelper.toGroupArtifactSet(resolvedDependencies); final Set<String> alreadyExcluded = new HashSet<>(); List<File> jarFiles = new ArrayList<>(); for (ArtifactDownloadReport adr : report.getAllArtifactsReports()) { Artifact artifact = adr.getArtifact(); String key = artifact.getModuleRevisionId().getOrganisation() + ":" + artifact.getModuleRevisionId().getName(); log.trace("Potentially filtering {} with key {}", artifact, key); if (alreadyResolved.contains(key)) { log.debug("Excluding {} (already added to classpath)", artifact); } else if (adr.getLocalFile() != null) { jarFiles.add(adr.getLocalFile()); } } return jarFiles; } }
IvyDependencyResolver implements DependencyResolver { @Override public List<File> resolve( Context context, List<Dependency> resolvedDependencies, List<Dependency> dependencies) throws DependencyResolveException, ParseException, IOException { Objects.requireNonNull(context, "context may not be null"); Objects.requireNonNull(resolvedDependencies, "resolvedDependencies may not be null"); Objects.requireNonNull(dependencies, "dependencies may not be null"); log.trace("Already resolved dependencies {}", resolvedDependencies); log.trace("Dependencies to resolve {}", dependencies); Message.setDefaultLogger(new FilteringIvyLogger()); MavenSettings mavenSettings = null; Path mavenSettingsFile = context.userDir().resolve(".m2/settings.xml"); if (Files.exists(mavenSettingsFile)) { try { mavenSettings = MavenSettings.parse(mavenSettingsFile); log.debug("Using maven settings {}", mavenSettingsFile); } catch (Exception e) { log.error("Unable to cleanly parse {}", mavenSettingsFile, e); } } final IvyAuthenticator authenticator = new IvyAuthenticator(); Authenticator.setDefault(authenticator); Ivy ivy = Ivy.newInstance(); IvySettings ivySettings = ivy.getSettings(); if (context.config().value(Config.KEY_DEPENDENCY_CLEAN, Boolean.class).getOr(Config.DEFAULT_DEPENDENCY_CLEAN)) { log.info("Cleaning dependency cache..."); ivy.getResolutionCacheManager().clean(); } dependencies.stream().forEach((d) -> { if (d.getVersion().endsWith("-SNAPSHOT")) { Path cachedFile = context.userDir().resolve(".ivy2/cache/" + d.getGroupId() + "/" + d.getArtifactId() + "/jars/" + d.getArtifactId() + "-" + d.getVersion() + ".jar"); if (Files.exists(cachedFile)) { log.trace("Deleting cached snapshot dependency {}", cachedFile); try { Files.delete(cachedFile); } catch (IOException e) { log.trace("Unable to delete", e.getMessage()); } } } }); IBiblioResolver mavenCentralResolver = new IBiblioResolver(); mavenCentralResolver.setM2compatible(true); mavenCentralResolver.setName("mavenCentral"); mavenCentralResolver.setUseMavenMetadata(true); final List<IBiblioResolver> additionalResolvers = new ArrayList<>(); final List<String> repositoryUrls = context != null && context.config() != null ? context.config().valueList(Config.KEY_REPOSITORIES).orNull() : null; if (repositoryUrls != null) { for (String repositoryUrl : repositoryUrls) { MavenRepositoryUrl mru = MavenRepositoryUrl.parse(repositoryUrl); MavenServer mavenServer = ofNullable(mavenSettings) .map(v -> v.findServerById(mru.getId())) .orElse(null); log.debug("Adding extra maven repo: {}->{}", mru.getId(), mru.getUrl()); if (mavenServer != null) { String host = mru.getUrl().getHost(); log.debug("Using maven settings credentials for id={}, host={}, username={}", mru.getId(), host, mavenServer.getUsername()); authenticator.addCredentials(host, mavenServer.getUsername(), mavenServer.getPassword()); } IBiblioResolver additionalResolver = new IBiblioResolver(); additionalResolver.setM2compatible(true); additionalResolver.setName(mru.getId()); additionalResolver.setUseMavenMetadata(true); additionalResolver.setRoot(mru.getUrl().toString()); additionalResolvers.add(additionalResolver); } } FileSystemResolver mavenLocalResolver = new FileSystemResolver(); mavenLocalResolver.setName("mavenLocal"); mavenLocalResolver.setLocal(true); File userHomeDir = context.userDir().toFile(); mavenLocalResolver.addArtifactPattern(userHomeDir.getAbsolutePath() + "/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]"); mavenLocalResolver.addIvyPattern(userHomeDir.getAbsolutePath() + "/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].pom"); mavenLocalResolver.setM2compatible(true); mavenLocalResolver.setChangingMatcher(PatternMatcher.REGEXP); mavenLocalResolver.setChangingPattern(".*-SNAPSHOT"); mavenLocalResolver.setCheckmodified(true); ChainResolver chainResolver = new ChainResolver(); chainResolver.setName("default"); chainResolver.add(mavenLocalResolver); chainResolver.add(mavenCentralResolver); chainResolver.setDual(true); additionalResolvers.forEach(v -> { chainResolver.add(v); }); ivySettings.addResolver(chainResolver); ivy.getSettings().setDefaultResolver(chainResolver.getName()); DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance( ModuleRevisionId.newInstance("blaze", "blaze", "resolver")); dependencies.stream() .map((d) -> { boolean isChanging = d.getVersion().endsWith("-SNAPSHOT"); return new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(d.getGroupId(), d.getArtifactId(), d.getVersion()), false, isChanging, true); }) .forEach((dd) -> { dd.addDependencyConfiguration("default", "default"); md.addDependency(dd); }); String[] confs = new String[] { "default" }; ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs); resolveOptions.setRefresh(true); ResolveReport report = ivy.resolve(md, resolveOptions); if (report.hasError()) { String firstMessage = (String)report.getAllProblemMessages().get(0); throw new DependencyResolveException(firstMessage); } final Set<String> alreadyResolved = DependencyHelper.toGroupArtifactSet(resolvedDependencies); final Set<String> alreadyExcluded = new HashSet<>(); List<File> jarFiles = new ArrayList<>(); for (ArtifactDownloadReport adr : report.getAllArtifactsReports()) { Artifact artifact = adr.getArtifact(); String key = artifact.getModuleRevisionId().getOrganisation() + ":" + artifact.getModuleRevisionId().getName(); log.trace("Potentially filtering {} with key {}", artifact, key); if (alreadyResolved.contains(key)) { log.debug("Excluding {} (already added to classpath)", artifact); } else if (adr.getLocalFile() != null) { jarFiles.add(adr.getLocalFile()); } } return jarFiles; }  }
IvyDependencyResolver implements DependencyResolver { @Override public List<File> resolve( Context context, List<Dependency> resolvedDependencies, List<Dependency> dependencies) throws DependencyResolveException, ParseException, IOException { Objects.requireNonNull(context, "context may not be null"); Objects.requireNonNull(resolvedDependencies, "resolvedDependencies may not be null"); Objects.requireNonNull(dependencies, "dependencies may not be null"); log.trace("Already resolved dependencies {}", resolvedDependencies); log.trace("Dependencies to resolve {}", dependencies); Message.setDefaultLogger(new FilteringIvyLogger()); MavenSettings mavenSettings = null; Path mavenSettingsFile = context.userDir().resolve(".m2/settings.xml"); if (Files.exists(mavenSettingsFile)) { try { mavenSettings = MavenSettings.parse(mavenSettingsFile); log.debug("Using maven settings {}", mavenSettingsFile); } catch (Exception e) { log.error("Unable to cleanly parse {}", mavenSettingsFile, e); } } final IvyAuthenticator authenticator = new IvyAuthenticator(); Authenticator.setDefault(authenticator); Ivy ivy = Ivy.newInstance(); IvySettings ivySettings = ivy.getSettings(); if (context.config().value(Config.KEY_DEPENDENCY_CLEAN, Boolean.class).getOr(Config.DEFAULT_DEPENDENCY_CLEAN)) { log.info("Cleaning dependency cache..."); ivy.getResolutionCacheManager().clean(); } dependencies.stream().forEach((d) -> { if (d.getVersion().endsWith("-SNAPSHOT")) { Path cachedFile = context.userDir().resolve(".ivy2/cache/" + d.getGroupId() + "/" + d.getArtifactId() + "/jars/" + d.getArtifactId() + "-" + d.getVersion() + ".jar"); if (Files.exists(cachedFile)) { log.trace("Deleting cached snapshot dependency {}", cachedFile); try { Files.delete(cachedFile); } catch (IOException e) { log.trace("Unable to delete", e.getMessage()); } } } }); IBiblioResolver mavenCentralResolver = new IBiblioResolver(); mavenCentralResolver.setM2compatible(true); mavenCentralResolver.setName("mavenCentral"); mavenCentralResolver.setUseMavenMetadata(true); final List<IBiblioResolver> additionalResolvers = new ArrayList<>(); final List<String> repositoryUrls = context != null && context.config() != null ? context.config().valueList(Config.KEY_REPOSITORIES).orNull() : null; if (repositoryUrls != null) { for (String repositoryUrl : repositoryUrls) { MavenRepositoryUrl mru = MavenRepositoryUrl.parse(repositoryUrl); MavenServer mavenServer = ofNullable(mavenSettings) .map(v -> v.findServerById(mru.getId())) .orElse(null); log.debug("Adding extra maven repo: {}->{}", mru.getId(), mru.getUrl()); if (mavenServer != null) { String host = mru.getUrl().getHost(); log.debug("Using maven settings credentials for id={}, host={}, username={}", mru.getId(), host, mavenServer.getUsername()); authenticator.addCredentials(host, mavenServer.getUsername(), mavenServer.getPassword()); } IBiblioResolver additionalResolver = new IBiblioResolver(); additionalResolver.setM2compatible(true); additionalResolver.setName(mru.getId()); additionalResolver.setUseMavenMetadata(true); additionalResolver.setRoot(mru.getUrl().toString()); additionalResolvers.add(additionalResolver); } } FileSystemResolver mavenLocalResolver = new FileSystemResolver(); mavenLocalResolver.setName("mavenLocal"); mavenLocalResolver.setLocal(true); File userHomeDir = context.userDir().toFile(); mavenLocalResolver.addArtifactPattern(userHomeDir.getAbsolutePath() + "/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]"); mavenLocalResolver.addIvyPattern(userHomeDir.getAbsolutePath() + "/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].pom"); mavenLocalResolver.setM2compatible(true); mavenLocalResolver.setChangingMatcher(PatternMatcher.REGEXP); mavenLocalResolver.setChangingPattern(".*-SNAPSHOT"); mavenLocalResolver.setCheckmodified(true); ChainResolver chainResolver = new ChainResolver(); chainResolver.setName("default"); chainResolver.add(mavenLocalResolver); chainResolver.add(mavenCentralResolver); chainResolver.setDual(true); additionalResolvers.forEach(v -> { chainResolver.add(v); }); ivySettings.addResolver(chainResolver); ivy.getSettings().setDefaultResolver(chainResolver.getName()); DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance( ModuleRevisionId.newInstance("blaze", "blaze", "resolver")); dependencies.stream() .map((d) -> { boolean isChanging = d.getVersion().endsWith("-SNAPSHOT"); return new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(d.getGroupId(), d.getArtifactId(), d.getVersion()), false, isChanging, true); }) .forEach((dd) -> { dd.addDependencyConfiguration("default", "default"); md.addDependency(dd); }); String[] confs = new String[] { "default" }; ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs); resolveOptions.setRefresh(true); ResolveReport report = ivy.resolve(md, resolveOptions); if (report.hasError()) { String firstMessage = (String)report.getAllProblemMessages().get(0); throw new DependencyResolveException(firstMessage); } final Set<String> alreadyResolved = DependencyHelper.toGroupArtifactSet(resolvedDependencies); final Set<String> alreadyExcluded = new HashSet<>(); List<File> jarFiles = new ArrayList<>(); for (ArtifactDownloadReport adr : report.getAllArtifactsReports()) { Artifact artifact = adr.getArtifact(); String key = artifact.getModuleRevisionId().getOrganisation() + ":" + artifact.getModuleRevisionId().getName(); log.trace("Potentially filtering {} with key {}", artifact, key); if (alreadyResolved.contains(key)) { log.debug("Excluding {} (already added to classpath)", artifact); } else if (adr.getLocalFile() != null) { jarFiles.add(adr.getLocalFile()); } } return jarFiles; }  @Override List<File> resolve(
            Context context,
            List<Dependency> resolvedDependencies,
            List<Dependency> dependencies); }
IvyDependencyResolver implements DependencyResolver { @Override public List<File> resolve( Context context, List<Dependency> resolvedDependencies, List<Dependency> dependencies) throws DependencyResolveException, ParseException, IOException { Objects.requireNonNull(context, "context may not be null"); Objects.requireNonNull(resolvedDependencies, "resolvedDependencies may not be null"); Objects.requireNonNull(dependencies, "dependencies may not be null"); log.trace("Already resolved dependencies {}", resolvedDependencies); log.trace("Dependencies to resolve {}", dependencies); Message.setDefaultLogger(new FilteringIvyLogger()); MavenSettings mavenSettings = null; Path mavenSettingsFile = context.userDir().resolve(".m2/settings.xml"); if (Files.exists(mavenSettingsFile)) { try { mavenSettings = MavenSettings.parse(mavenSettingsFile); log.debug("Using maven settings {}", mavenSettingsFile); } catch (Exception e) { log.error("Unable to cleanly parse {}", mavenSettingsFile, e); } } final IvyAuthenticator authenticator = new IvyAuthenticator(); Authenticator.setDefault(authenticator); Ivy ivy = Ivy.newInstance(); IvySettings ivySettings = ivy.getSettings(); if (context.config().value(Config.KEY_DEPENDENCY_CLEAN, Boolean.class).getOr(Config.DEFAULT_DEPENDENCY_CLEAN)) { log.info("Cleaning dependency cache..."); ivy.getResolutionCacheManager().clean(); } dependencies.stream().forEach((d) -> { if (d.getVersion().endsWith("-SNAPSHOT")) { Path cachedFile = context.userDir().resolve(".ivy2/cache/" + d.getGroupId() + "/" + d.getArtifactId() + "/jars/" + d.getArtifactId() + "-" + d.getVersion() + ".jar"); if (Files.exists(cachedFile)) { log.trace("Deleting cached snapshot dependency {}", cachedFile); try { Files.delete(cachedFile); } catch (IOException e) { log.trace("Unable to delete", e.getMessage()); } } } }); IBiblioResolver mavenCentralResolver = new IBiblioResolver(); mavenCentralResolver.setM2compatible(true); mavenCentralResolver.setName("mavenCentral"); mavenCentralResolver.setUseMavenMetadata(true); final List<IBiblioResolver> additionalResolvers = new ArrayList<>(); final List<String> repositoryUrls = context != null && context.config() != null ? context.config().valueList(Config.KEY_REPOSITORIES).orNull() : null; if (repositoryUrls != null) { for (String repositoryUrl : repositoryUrls) { MavenRepositoryUrl mru = MavenRepositoryUrl.parse(repositoryUrl); MavenServer mavenServer = ofNullable(mavenSettings) .map(v -> v.findServerById(mru.getId())) .orElse(null); log.debug("Adding extra maven repo: {}->{}", mru.getId(), mru.getUrl()); if (mavenServer != null) { String host = mru.getUrl().getHost(); log.debug("Using maven settings credentials for id={}, host={}, username={}", mru.getId(), host, mavenServer.getUsername()); authenticator.addCredentials(host, mavenServer.getUsername(), mavenServer.getPassword()); } IBiblioResolver additionalResolver = new IBiblioResolver(); additionalResolver.setM2compatible(true); additionalResolver.setName(mru.getId()); additionalResolver.setUseMavenMetadata(true); additionalResolver.setRoot(mru.getUrl().toString()); additionalResolvers.add(additionalResolver); } } FileSystemResolver mavenLocalResolver = new FileSystemResolver(); mavenLocalResolver.setName("mavenLocal"); mavenLocalResolver.setLocal(true); File userHomeDir = context.userDir().toFile(); mavenLocalResolver.addArtifactPattern(userHomeDir.getAbsolutePath() + "/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]"); mavenLocalResolver.addIvyPattern(userHomeDir.getAbsolutePath() + "/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].pom"); mavenLocalResolver.setM2compatible(true); mavenLocalResolver.setChangingMatcher(PatternMatcher.REGEXP); mavenLocalResolver.setChangingPattern(".*-SNAPSHOT"); mavenLocalResolver.setCheckmodified(true); ChainResolver chainResolver = new ChainResolver(); chainResolver.setName("default"); chainResolver.add(mavenLocalResolver); chainResolver.add(mavenCentralResolver); chainResolver.setDual(true); additionalResolvers.forEach(v -> { chainResolver.add(v); }); ivySettings.addResolver(chainResolver); ivy.getSettings().setDefaultResolver(chainResolver.getName()); DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance( ModuleRevisionId.newInstance("blaze", "blaze", "resolver")); dependencies.stream() .map((d) -> { boolean isChanging = d.getVersion().endsWith("-SNAPSHOT"); return new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(d.getGroupId(), d.getArtifactId(), d.getVersion()), false, isChanging, true); }) .forEach((dd) -> { dd.addDependencyConfiguration("default", "default"); md.addDependency(dd); }); String[] confs = new String[] { "default" }; ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs); resolveOptions.setRefresh(true); ResolveReport report = ivy.resolve(md, resolveOptions); if (report.hasError()) { String firstMessage = (String)report.getAllProblemMessages().get(0); throw new DependencyResolveException(firstMessage); } final Set<String> alreadyResolved = DependencyHelper.toGroupArtifactSet(resolvedDependencies); final Set<String> alreadyExcluded = new HashSet<>(); List<File> jarFiles = new ArrayList<>(); for (ArtifactDownloadReport adr : report.getAllArtifactsReports()) { Artifact artifact = adr.getArtifact(); String key = artifact.getModuleRevisionId().getOrganisation() + ":" + artifact.getModuleRevisionId().getName(); log.trace("Potentially filtering {} with key {}", artifact, key); if (alreadyResolved.contains(key)) { log.debug("Excluding {} (already added to classpath)", artifact); } else if (adr.getLocalFile() != null) { jarFiles.add(adr.getLocalFile()); } } return jarFiles; }  @Override List<File> resolve(
            Context context,
            List<Dependency> resolvedDependencies,
            List<Dependency> dependencies);  }