Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue#100 #279

Closed
wants to merge 1 commit into from
Closed

fix issue#100 #279

wants to merge 1 commit into from

Conversation

wangliang181230
Copy link

@wangliang181230 wangliang181230 commented May 31, 2022

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
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