Uploaded image for project: 'Maven Shade Plugin'
  1. Maven Shade Plugin
  2. MSHADE-36

Add option to include dependency reduced POM instead of original one

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1
    • 3.3.0
    • None

    Description

      The dependency reduced pom needs to replace the packaged pom at:

      META-INF/maven/<groupId>/<artifactId>/pom.xml

      This will allow tools that use this metadata to read the correct shaded dependencies (e.g. maven-runtime).

      Attachments

        Issue Links

          Activity

            Would creating a ResourceTransformer be the best approach?

            robertburrelldonkin Robert Burrell Donkin added a comment - Would creating a ResourceTransformer be the best approach?
            hhuynh Hung Huynh added a comment -

            I prefer this as a built-in default feature since it's expected rather an exception. However, users should be able to turn this off if they want to

            hhuynh Hung Huynh added a comment - I prefer this as a built-in default feature since it's expected rather an exception. However, users should be able to turn this off if they want to
            michael-o Michael Osipov added a comment -

            This issue has been auto closed because it has been inactive for a long period of time. If you think this issue still persists, retest your problem with the most recent version of Maven and the affected component, reopen and post your results.

            michael-o Michael Osipov added a comment - This issue has been auto closed because it has been inactive for a long period of time. If you think this issue still persists, retest your problem with the most recent version of Maven and the affected component, reopen and post your results.
            vy Volkan Yazici added a comment -

            michael-o, I think this is still a valid bug. Here is a test case to reproduce it:

            This is how my pom.xml looks like:

            pom.xml
            <?xml version="1.0" encoding="UTF-8"?>
            <project xmlns="http://maven.apache.org/POM/4.0.0"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
                <modelVersion>4.0.0</modelVersion>
            
                <groupId>com.vlkan</groupId>
                <artifactId>maven-shade-plugin-pom-bug</artifactId>
                <version>1.0-SNAPSHOT</version>
            
                <dependencies>
                    <dependency>
                        <groupId>net.java.dev.jna</groupId>
                        <artifactId>jna</artifactId>
                        <version>4.2.1</version>
                    </dependency>
                </dependencies>
            
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-shade-plugin</artifactId>
                            <version>2.4.3</version>
                            <executions>
                                <execution>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>shade</goal>
                                    </goals>
                                    <configuration>
                                        <artifactSet>
                                            <includes>
                                                <include>net.java.dev.jna:jna</include>
                                            </includes>
                                        </artifactSet>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            
            </project>
            

            Here, since I am including net.java.dev.jna:jna within the final artifact, I would expect it to be removed from the META-INF/maven/com.vlkan/maven-shade-plugin-pom-bug/pom.xml file. But apparently, it is not:

            $ mvn package
            $ unzip -p target/maven-shade-plugin-pom-bug-1.0-SNAPSHOT.jar META-INF/maven/com.vlkan/maven-shade-plugin-pom-bug/pom.xml
            <?xml version="1.0" encoding="UTF-8"?>
            <project xmlns="http://maven.apache.org/POM/4.0.0"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
                <modelVersion>4.0.0</modelVersion>
            
                <groupId>com.vlkan</groupId>
                <artifactId>maven-shade-plugin-pom-bug</artifactId>
                <version>1.0-SNAPSHOT</version>
            
                <dependencies>
                    <dependency>
                        <groupId>net.java.dev.jna</groupId>
                        <artifactId>jna</artifactId>
                        <version>4.2.1</version>
                    </dependency>
                </dependencies>
            
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-shade-plugin</artifactId>
                            <version>2.4.3</version>
                            <executions>
                                <execution>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>shade</goal>
                                    </goals>
                                    <configuration>
                                        <artifactSet>
                                            <includes>
                                                <include>net.java.dev.jna:jna</include>
                                            </includes>
                                        </artifactSet>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            
            </project>
            

            Per see, net.java.dev.jna:jna still appears as a dependency, which actually is not any more. It should have been removed from the dependencies of the final artifact.

            michael-o, can we re-open this issue? (I suppose I am lacking the sufficient rights to do so.)

            vy Volkan Yazici added a comment - michael-o , I think this is still a valid bug. Here is a test case to reproduce it: This is how my pom.xml looks like: pom.xml <?xml version= "1.0" encoding= "UTF-8" ?> <project xmlns= "http: //maven.apache.org/POM/4.0.0" xmlns:xsi= "http: //www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http: //maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelVersion>4.0.0</modelVersion> <groupId>com.vlkan</groupId> <artifactId>maven-shade-plugin-pom-bug</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> <version>4.2.1</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.3</version> <executions> <execution> <phase> package </phase> <goals> <goal>shade</goal> </goals> <configuration> <artifactSet> <includes> <include>net.java.dev.jna:jna</include> </includes> </artifactSet> </configuration> </execution> </executions> </plugin> </plugins> </build> </project> Here, since I am including net.java.dev.jna:jna within the final artifact, I would expect it to be removed from the META-INF/maven/com.vlkan/maven-shade-plugin-pom-bug/pom.xml file. But apparently, it is not: $ mvn package $ unzip -p target/maven-shade-plugin-pom-bug-1.0-SNAPSHOT.jar META-INF/maven/com.vlkan/maven-shade-plugin-pom-bug/pom.xml <?xml version= "1.0" encoding= "UTF-8" ?> <project xmlns= "http: //maven.apache.org/POM/4.0.0" xmlns:xsi= "http: //www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http: //maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelVersion>4.0.0</modelVersion> <groupId>com.vlkan</groupId> <artifactId>maven-shade-plugin-pom-bug</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> <version>4.2.1</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.3</version> <executions> <execution> <phase> package </phase> <goals> <goal>shade</goal> </goals> <configuration> <artifactSet> <includes> <include>net.java.dev.jna:jna</include> </includes> </artifactSet> </configuration> </execution> </executions> </plugin> </plugins> </build> </project> Per see, net.java.dev.jna:jna still appears as a dependency, which actually is not any more. It should have been removed from the dependencies of the final artifact. michael-o , can we re-open this issue? (I suppose I am lacking the sufficient rights to do so.)
            michael-o Michael Osipov added a comment -

            Reopening per user request.

            michael-o Michael Osipov added a comment - Reopening per user request.

            Does anyone have a patch for this issue? If not, where would be a good place to start bug hunting?

            exabrial Jonathan S Fisher added a comment - Does anyone have a patch for this issue? If not, where would be a good place to start bug hunting?
            m-manu Manu Manjunath added a comment -

            Can you guys at least provide us a flag in shade plugin like this:

            <useDependencyReducedPomInJar>true</useDependencyReducedPomInJar>
            

            When set to true, the jar that is built should contain pom.xml whose content is same dependency-reduced-pom.xml that shade plugin generates. That way:

            1. Backword compatibility is maintained
            2. Developers can keep this false if some of the dependent code is dynamically loading classes, using classloader.
            m-manu Manu Manjunath added a comment - Can you guys at least provide us a flag in shade plugin like this: <useDependencyReducedPomInJar> true </useDependencyReducedPomInJar> When set to true, the jar that is built should contain pom.xml whose content is same dependency-reduced-pom.xml that shade plugin generates. That way: Backword compatibility is maintained Developers can keep this false if some of the dependent code is dynamically loading classes, using classloader.
            bentatham@nanometrics.ca Ben Tatham added a comment -

            Would fixing this allow the dependency-reduced-pom to be used as the pom of the module in a reactor build?

             

            bentatham@nanometrics.ca Ben Tatham added a comment - Would fixing this allow the dependency-reduced-pom to be used as the pom of the module in a reactor build?  
            bentatham@nanometrics.ca Ben Tatham added a comment -

            Would fixing this allow the dependency-reduced-pom to be used as the pom of the module in a reactor build?

             

            bentatham@nanometrics.ca Ben Tatham added a comment - Would fixing this allow the dependency-reduced-pom to be used as the pom of the module in a reactor build?  
            nielsbasjes Niels Basjes added a comment -

            I put up a pull request with a proposed fix for this:

            https://github.com/apache/maven-shade-plugin/pull/25

            nielsbasjes Niels Basjes added a comment - I put up a pull request with a proposed fix for this: https://github.com/apache/maven-shade-plugin/pull/25
            nielsbasjes Niels Basjes added a comment -

            bentatham@nanometrics.ca : When building a multi module project there will still be problems regarding the dependencies in the other modules.

            I recently wrote a page about that how I solved that in my own project: https://yauaa.basjes.nl/NOTES-shading-dependencies.html

            Essentially what works for me:

            • Library has dependencies (shaded into the jar)
            • Other modules use it as a dependency, exclude the shaded dependencies, re-include the shaded dependencies as 'provided'.
            nielsbasjes Niels Basjes added a comment - bentatham@nanometrics.ca  : When building a multi module project there will still be problems regarding the dependencies in the other modules. I recently wrote a page about that how I solved that in my own project:  https://yauaa.basjes.nl/NOTES-shading-dependencies.html Essentially what works for me: Library has dependencies (shaded into the jar) Other modules use it as a dependency, exclude the shaded dependencies, re-include the shaded dependencies as 'provided'.
            alexey.subach Alexey Subach added a comment -

            Dear Team,
            I think this is a terribly useful feature - is there any chance it can be given a bit more priority?

            alexey.subach Alexey Subach added a comment - Dear Team, I think this is a terribly useful feature - is there any chance it can be given a bit more priority?
            michael-o Michael Osipov added a comment -

            Waiting for the PR to be updated...

            michael-o Michael Osipov added a comment - Waiting for the PR to be updated...
            michael-o Michael Osipov added a comment - Fixed with 83c123d1f9c5f6927af2aca12ee322b5168a7c63 .
            hudson Hudson added a comment -

            Build succeeded in Jenkins: Maven » Maven TLP » maven-shade-plugin » master #46

            See https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven-shade-plugin/job/master/46/

            hudson Hudson added a comment - Build succeeded in Jenkins: Maven » Maven TLP » maven-shade-plugin » master #46 See https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven-shade-plugin/job/master/46/
            jdimeo John Dimeo added a comment -

            Thanks for the work on this, but something very very strange just happened: one of my child modules of one of my multi-module projects seemigly used the new dep reduced POM as it's "real" POM and it then removed all transitive dependencies (without me telling the plugin to do so) for downstream Maven builds. I'm not sure how or why it happened, but just a heads up.  From my perspective, I just updated the Maven shade plugin and transitive dependencies stopped working- no configuration was changed. The workaround is to set useDependencyReducedPomInJar back to false (since thankfully no one downstream is using it).

            jdimeo John Dimeo added a comment - Thanks for the work on this, but something very very strange just happened: one of my child modules of one of my multi-module projects seemigly used the new dep reduced POM as it's "real" POM and it then removed all transitive dependencies (without me telling the plugin to do so) for downstream Maven builds. I'm not sure how or why it happened, but just a heads up.  From my perspective, I just updated the Maven shade plugin and transitive dependencies stopped working- no configuration was changed. The workaround is to set useDependencyReducedPomInJar back to false (since thankfully no one downstream is using it).
            michael-o Michael Osipov added a comment -

            How, the value is by default false? Can you reproduce in isolation?

            michael-o Michael Osipov added a comment - How, the value is by default false ? Can you reproduce in isolation?

            People

              michael-o Michael Osipov
              markh Mark Hobson
              Votes:
              8 Vote for this issue
              Watchers:
              14 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: