Skip to content

fix issue#100 - #279

Closed
wangliang181230 wants to merge 1 commit into
mojohaus:masterfrom
wangliang181230:fix-issue-100
Closed

fix issue#100#279
wangliang181230 wants to merge 1 commit into
mojohaus:masterfrom
wangliang181230:fix-issue-100

Conversation

@wangliang181230

@wangliang181230 wangliang181230 commented May 31, 2022

Copy link
Copy Markdown

fixes #100

The maven-shade-plugin will use the project.getOriginalModel() to create the shaded-pom. So reset the version of the parent can fix #100.


Relevant source code of maven-shade-plugin:

ShadeMojo.java

public class ShadeMojo extends AbstractMojo {
    //……

    private void createDependencyReducedPom( Set<String> artifactsToRemove ) {
        //……

        Model model = project.getOriginalModel();

        //……

        // Check to see if we have a reduction and if so rewrite the POM.
        rewriteDependencyReducedPomIfWeHaveReduction( dependencies, modified, transitiveDeps, model );
    }

    private void rewriteDependencyReducedPomIfWeHaveReduction( List<Dependency> dependencies, boolean modified, List<Dependency> transitiveDeps, Model model ) throws IOException, ProjectBuildingException, DependencyGraphBuilderException {
        //……

        try {
            PomWriter.write( w, model, true );
        } finally {
            //……
        }

        //……
    }

    //……
}

PomWriter.java

public class PomWriter {
    //……

    public static void write( Writer w, Model newModel, boolean namespaceDeclaration ) throws IOException {
        //……

        MavenJDOMWriter writer = new MavenJDOMWriter();

        //……

        writer.write( newModel, doc, w, format );
    }

    //……
}

MavenJDOMWriter.java

public class MavenJDOMWriter {
    //……

    protected void updateParent( Parent value, String xmlTag, Counter counter, Element element ) {
        boolean shouldExist = value != null;
        Element root = updateElement( counter, element, xmlTag, shouldExist );
        if ( shouldExist ) {
            Counter innerCount = new Counter( counter.getDepth() + 1 );
            findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
            findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
            findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
            findAndReplaceSimpleElement( innerCount, root, "relativePath", value.getRelativePath(), "../pom.xml" );
        }
    }

    //……

}

@wangliang181230

Copy link
Copy Markdown
Author

The better PR: #281

@wangliang181230
wangliang181230 deleted the fix-issue-100 branch June 1, 2022 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flatten-vs-shade incompatibility

1 participant