Skip to content

Commit

Permalink
Do not upgrade test scope dependencies by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasHofman committed Nov 24, 2023
1 parent 18d53f9 commit be46f08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Additional configuration - all of these are optional:
prefixes should not be modified.
* `ignoreModules`: Comma delimited list of "groupId:artifactId" strings, representing project submodules that should not
be processed (no dependencies or properties in given modules will be modified).
* `ignoreTestDependencies`: If true, dependencies that are only in the test scope will not be upgraded. True by default.
* `injectTransitiveDependencies`: If true, transitive dependencies are upgraded too, by injecting new declarations into
the \<dependencyManagement\> section.
* `overrideProperties`: Comma delimited list of "propertyName=newValue" strings, meaning that diven properties (in any
project module) should be overridden to given values. This takes preference over modifications inferred from the
channel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ public class UpgradeComponentsMojo extends AbstractMojo {
@Parameter(property = "copyExclusionsFrom")
String copyExclusionsFrom;

@Parameter(property = "ignoreTestDependencies", defaultValue = "true")
boolean ignoreTestDependencies;

@Inject
DependencyGraphBuilder dependencyGraphBuilder;

Expand Down Expand Up @@ -571,6 +574,11 @@ private List<Pair<Dependency, String>> findDependenciesToUpgrade(
getLog().warn("Resolved dependency has version with property: " + artifactRef);
continue;
}
if ("test".equals(dependency.getScope()) && ignoreTestDependencies) {
getLog().info("Skipping dependency (ignored scope): "
+ artifactRef.asProjectVersionRef().toString());
continue;
}


try {
Expand Down Expand Up @@ -785,9 +793,14 @@ private Map<ArtifactRef, Collection<ProjectRef>> collectUndeclaredDependencies()
visitor.getNodes().forEach(node -> {
ArtifactRef artifact = toArtifactRef(node.getArtifact());
Collection<ProjectRef> exclusions = artifactExclusions.get(artifact);
if (!declaredDependencies.contains(artifact.asProjectRef())) {
undeclaredDependencies.put(artifact, exclusions);
if (declaredDependencies.contains(artifact.asProjectRef())) {
return;
}
if ("test".equals(node.getArtifact().getScope()) && ignoreTestDependencies) {
// Ignore test scope undeclared dependencies entirely.
return;
}
undeclaredDependencies.put(artifact, exclusions);
});
}
return undeclaredDependencies;
Expand Down

0 comments on commit be46f08

Please sign in to comment.