Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MENFORCER-470] AdvancedDependencyConvergence rule #246

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import javax.inject.Named;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.enforcer.rules.AbstractStandardEnforcerRule;
import org.apache.maven.enforcer.rules.utils.ArtifactUtils;
Expand All @@ -35,9 +37,6 @@
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;

import static org.apache.maven.artifact.Artifact.SCOPE_PROVIDED;
import static org.apache.maven.artifact.Artifact.SCOPE_TEST;

/**
* @author <a href="mailto:rex@e-hoffman.org">Rex Hoffman</a>
*/
Expand All @@ -50,6 +49,8 @@ public final class DependencyConvergence extends AbstractStandardEnforcerRule {

private List<String> excludes;

private List<String> scopes = Arrays.asList(Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_SYSTEM);

private DependencyVersionMap dependencyVersionMap;

private final ResolveUtil resolveUtil;
Expand All @@ -71,8 +72,7 @@ public boolean selectDependency(Dependency dependency) {
return !dependency.isOptional()
// regular scope selectors only discard transitive dependencies
// and always allow direct dependencies
&& !dependency.getScope().equals(SCOPE_TEST)
&& !dependency.getScope().equals(SCOPE_PROVIDED);
&& scopes.contains(dependency.getScope());
}

@Override
Expand Down Expand Up @@ -142,7 +142,7 @@ private String buildConvergenceErrorMsg(List<DependencyNode> nodeList) {
@Override
public String toString() {
return String.format(
"DependencyConvergence[includes=%s, excludes=%s, uniqueVersions=%b]",
includes, excludes, uniqueVersions);
"DependencyConvergence[includes=%s, excludes=%s, uniqueVersions=%b, scopes=%s]",
slawekjaranowski marked this conversation as resolved.
Show resolved Hide resolved
includes, excludes, uniqueVersions, String.join(",", scopes));
}
}
7 changes: 7 additions & 0 deletions enforcer-rules/src/site/apt/dependencyConvergence.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ and
* <<excludes>> - A list of artifacts for which dependency convergence should not be enforced. These are exceptions
to the includes.

* <<scopes>> - A list of scopes of artifacts for which dependency convergence should be enforced. Not specifying
any scopes is interpreted as having the following scopes activated: compile, runtime, system.

[]

The format for artifacts is groupId[:artifactId][:version][:type][:scope][:classifier] where artifactId, version,
Expand All @@ -147,6 +150,10 @@ and

+---------------------------------------------
<dependencyConvergence>
<scopes>
<scope>compile</scope>
<scope>runtime</scope>
</scopes>
<includes>
<include>org.slf4j</include>
<include>org.apache.commons</include>
Expand Down