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

shadeSourcesContent is broken when combined with partial relocation

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.3, 3.0.0
    • 3.3.0

    Description

      per description in https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#shadeSourcesContent, when set it to true,
      "it will attempt to shade the contents of the java source files when creating the sources jar." However, it seems will blindly shade all the source files include those are excluded from relocation rules.

      This could be illustrated with a simple example:

      Assume there are two classes defined in two packages as below:

      A.java
      package com.fake.fooA;
      import com.fake.fooB;
      public Class A {}
      
      B.java
      package com.fake.fooB;
      import com.fake.fooA;
      public class B {}
      

      and the maven config looks like:

           <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-shade-plugin</artifactId>
              <version>2.4.3</version>
              <executions>
                <!-- Run shade goal on package phase -->
                <execution>
                  <phase>package</phase>
                  <goals>
                    <goal>shade</goal>
                  </goals>
                  <configuration>
                    <shadedArtifactAttached>false</shadedArtifactAttached>
                    <createSourcesJar>true</createSourcesJar>
                    <shadeSourcesContent>true</shadeSourcesContent>
                    <relocations>
                      <relocation>
                        <pattern>com.fake</pattern>
                        <shadedPattern>.com.fake.shaded</shadedPattern>
                        <excludes>
                          <exclude>com.fake.fooA.*</exclude>
                        </excludes>
                      </relocation>
                     </relocations> 
      

      Then the shade plugin will modify the B's source file to be:

      package com.fake.shaded.fooB;
      import com.fake.shaded.fooA;
      public class B {}
      

      Notice that package A's path was also updated, which is wrong as it's not got relocated.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            hboutemy Herve Boutemy
            snyangzhenyu99 Zhenyu Yang
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment