be more descriptive of what is banned and its chain

This commit is contained in:
2026-03-06 12:00:37 -05:00
parent 46e19caa08
commit fd5e91fe1c
3 changed files with 16 additions and 12 deletions
@@ -90,6 +90,7 @@ public class BanDependencyFilter implements DependencyFilter {
// plugin resolution downloads banned dependencies unless we fail now; not later
throw new BannedDependencyException(node, parents);
} else {
this.logger.warn("Banned dependency: " + depArtifact + " => " + parents);
return true;
}
}
@@ -90,7 +90,8 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
BanDependencyFilter depFilter = new BanDependencyFilter(
config.getIncludeArtifacts(),
config.getExcludeArtifacts());
depFilter.setFailFast(true);
//depFilter.setFailFast(true);
boolean fail = false;
MavenProject project = session.getCurrentProject();
@@ -99,14 +100,11 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
this.logger.debug("Evaluating plugin dependencies: {}", plugin);
Artifact artifact = new DefaultArtifact(plugin.getId());
try {
DependencyNode depNodeRoot = this.pluginDepResolver.resolve(plugin, artifact, depFilter, project.getRemotePluginRepositories(), session.getRepositorySession());
List<Dependency> bannedDependencies = this.crawlDependencyTree(depNodeRoot, depFilter);
if (!bannedDependencies.isEmpty())
throw new MavenExecutionException("Banned dependencies were detected in plugin '" + plugin + "': " + bannedDependencies, project.getFile());
} catch (BannedDependencyException bde) {
throw new BannedPluginException(plugin, bde);
}
DependencyNode depNodeRoot = this.pluginDepResolver.resolve(plugin, artifact, depFilter, project.getRemotePluginRepositories(), session.getRepositorySession());
List<Dependency> bannedDependencies = this.crawlDependencyTree(depNodeRoot, depFilter);
if (!bannedDependencies.isEmpty())
fail = true;
//throw new MavenExecutionException("Banned dependencies were detected in plugin '" + plugin.getKey() + "': " + bannedDependencies, project.getFile());
}
} catch (BannedArtifactException bae) {
throw new MavenExecutionException(bae.getMessage(), bae);
@@ -114,19 +112,24 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
throw new MavenExecutionException(pre.getMessage(), pre);
}
depFilter.setFailFast(false);
//depFilter.setFailFast(false);
DefaultDependencyResolutionRequest request = new DefaultDependencyResolutionRequest(project, session.getRepositorySession());
request.setResolutionFilter(depFilter);
try {
// TODO somehow get the chain
DependencyResolutionResult result = this.projDepResolver.resolve(request);
List<Dependency> bannedDependencies = result.getDependencies();
if (!bannedDependencies.isEmpty())
throw new MavenExecutionException("Banned dependencies were detected: " + bannedDependencies, project.getFile());
fail = true;
//throw new MavenExecutionException("Banned dependencies were detected: " + bannedDependencies, project.getFile());
} catch (DependencyResolutionException dre) {
throw new MavenExecutionException(dre.getMessage(), dre);
}
if (fail)
throw new MavenExecutionException("Banned dependencies were detected; see warnings: ", project.getFile());
}
private BanConfiguration getConfiguration(MavenSession session) throws MavenExecutionException {
@@ -25,7 +25,7 @@ public class BannedArtifactException extends RuntimeException {
private static String buildMessage(Artifact descendant, Iterable<Artifact> ancestors) {
StringBuilder sb = new StringBuilder();
sb.append("Banned artifact: ").append(descendant);
sb.append(descendant);
if (ancestors != null) {
for (Artifact ancestor : ancestors) {
sb.append(" from ");