Skip to content

Commit

Permalink
Ignore dependencies with specific scopes from the DepClean analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarsotovalero committed May 7, 2020
1 parent e092b1f commit 3986c40
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 234 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ The Maven plugin can be configured with the following additional parameters.

| Name | Type | Description |
|:----------|:-------------:| :-------------|
| `<ignoreDependencies>` | `Set<String>` | Add a list of dependencies, identified by their coordinates, to be ignored by DepClean during the analysis and considered as used dependencies. Useful to override incomplete result caused by bytecode-level analysis. Dependency format is `groupId:artifactId:version`.|
| `<ignoreDependencies>` | `Set<String>` | Add a list of dependencies, identified by their coordinates, to be ignored by DepClean during the analysis and considered as used dependencies. Useful to override incomplete result caused by bytecode-level analysis. **Dependency format is:** `groupId:artifactId:version`.|
| `<ignoreScopes>` | `Set<String>` | Add a list of scopes, to be ignored by DepClean during the analysis. Useful to not analyze dependencies with scopes that are not needed at runtime. **Valid scopes are:** `compile`, `provided`, `test`, `runtime`, `system`, `import`. **Default value is:** ``.|
| `<createPomDebloated>` | `boolean` | If this is true, DepClean creates a debloated version of the pom without unused dependencies called `debloated-pom.xml`, in root of the project. **Default value is:** `false`.|
| `<failIfUnusedDependency>` | `boolean` | If this is true, and DepClean reported any unused dependency in the dependency tree, the build fails immediately after running DepClean. **Default value is:** `false`.|
| `<skipDepClean>` | `boolean` | Skip plugin execution completely. **Default value is:** `false`.|




## Installing and building from source

Prerequisites:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public class DepCleanMojo extends AbstractMojo
private Set<String> ignoreDependencies;

/**
* Exclude dependencies with specific scopes from the DepClean analysis.
* Ignore dependencies with specific scopes from the DepClean analysis.
*/
@Parameter(property = "exclude.scopes")
private Set<String> excludeScope;
@Parameter(property = "ignore.scopes")
private Set<String> ignoreScopes;

/**
* If this is true, and DepClean reported any unused dependency in the dependency tree,
Expand Down Expand Up @@ -194,14 +194,13 @@ public void execute() throws MojoExecutionException, MojoFailureException
unusedUndeclaredArtifacts.removeAll(unusedDeclaredArtifacts);

/* Exclude dependencies with specific scopes from the DepClean analysis */
if (excludeScope.size() >= 1) {
if (ignoreScopes.size() >= 1) {
usedUndeclaredArtifacts = excludeScope(usedUndeclaredArtifacts);
usedDeclaredArtifacts = excludeScope(usedDeclaredArtifacts);
unusedDeclaredArtifacts = excludeScope(unusedDeclaredArtifacts);
unusedUndeclaredArtifacts = excludeScope(unusedUndeclaredArtifacts);
}


/* Use artifacts coordinates for the report instead of the Artifact object */
Set<String> usedDeclaredArtifactsCoordinates = new HashSet<>();
usedDeclaredArtifacts.forEach(s -> usedDeclaredArtifactsCoordinates.add(s.getGroupId() + ":" + s.getArtifactId() + ":" + s.getVersion() + ":" + s.getScope()));
Expand Down Expand Up @@ -342,7 +341,7 @@ private Set<Artifact> excludeScope(Set<Artifact> artifacts)
Iterator<Artifact> iterator = artifacts.iterator();
while (iterator.hasNext()) {
Artifact artifact = iterator.next();
if (!excludeScope.contains(artifact.getScope())) {
if (!ignoreScopes.contains(artifact.getScope())) {
nonExcludedArtifacts.add(artifact);
}
}
Expand Down
Loading

0 comments on commit 3986c40

Please sign in to comment.