Skip to content

Commit

Permalink
[MSHADE-413] Fix endless loop caused by manipulating shared objects
Browse files Browse the repository at this point in the history
Maven objects (like `Dependency` or `Model`) returned by Maven must not
be modified. Doing so will result in endless loops or incorrect builds.
  • Loading branch information
snazy committed Mar 21, 2022
1 parent aa019ca commit e888434
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
Expand Up @@ -1083,14 +1083,20 @@ private void createDependencyReducedPom( Set<String> artifactsToRemove )
// we'll figure out the exclusions in a bit.
transitiveDeps.add( dep );
}
List<Dependency> origDeps = project.getDependencies();

if ( promoteTransitiveDependencies )
Model model = project.getOriginalModel();

// MSHADE-413: Must not use objects (for example `Model` or `Dependency`) that are "owned
// by Maven" and being used by other projects/plugins. Modifying those will break the
// correctness of the build - or cause an endless loop.
List<Dependency> origDeps = new ArrayList<>();
List<Dependency> source = promoteTransitiveDependencies ? transitiveDeps : project.getDependencies();
for ( Dependency d : source )
{
origDeps = transitiveDeps;
origDeps.add( d.clone() );
}
model = model.clone();

Model model = project.getOriginalModel();
// MSHADE-185: We will remove all system scoped dependencies which usually
// have some kind of property usage. At this time the properties within
// such things are already evaluated.
Expand Down

0 comments on commit e888434

Please sign in to comment.