Skip to content

Commit

Permalink
remove test before building tree
Browse files Browse the repository at this point in the history
  • Loading branch information
suztomo committed Aug 11, 2022
1 parent 88ce8f4 commit 5311c18
Showing 1 changed file with 5 additions and 30 deletions.
35 changes: 5 additions & 30 deletions src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -1089,18 +1089,12 @@ private void createFlattenedDependenciesAll( List<Dependency> projectDependencie
final Queue<DependencyNode> dependencyNodeLinkedList = new LinkedList<>();
final Set<String> processedDependencies = new HashSet<>();

final Set<String> testScopeProjectDependencies = new HashSet<>();
for (Dependency projectDependency : projectDependencies)
{
if ("test".equals(projectDependency.getScope()))
{
String managementKey = projectDependency.getManagementKey();
testScopeProjectDependencies.add(managementKey);
}
}

final Artifact projectArtifact = this.project.getArtifact();

// The test-scope project dependencies will hinder transitive dependencies by marking them
// as 'omitted for duplicate.'
this.project.getDependencies().removeIf(dependency -> "test".equals(dependency.getScope()));

final DependencyNode dependencyNode = this.dependencyTreeBuilder.buildDependencyTree(this.project,
this.localRepository, null);

Expand All @@ -1122,26 +1116,7 @@ private void createFlattenedDependenciesAll( List<Dependency> projectDependencie
}
if (node.getState() != DependencyNode.INCLUDED)
{
if (node.getState() == DependencyNode.OMITTED_FOR_DUPLICATE)
{
Artifact artifact = node.getArtifact();
// The same format as org.apache.maven.model.Dependency.getManagementKey()
String managementKey = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType()
+ (artifact.getClassifier() != null ? ":" + artifact.getClassifier() : "");
if (testScopeProjectDependencies.contains(managementKey))
{
// The tree should not omit this node, because the project dependency which supersedes this node
// will be removed due to its test-scope.
dependencyNodeLinkedList.add(node);
return true;
}
else
{
return false;
}
} else {
return false;
}
return false;
}
if (node.getArtifact().isOptional())
{
Expand Down

0 comments on commit 5311c18

Please sign in to comment.