[ 
https://issues.apache.org/jira/browse/MSHADE-217?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17314394#comment-17314394
 ] 
Alexander Kriegisch edited comment on MSHADE-217 at 4/4/21, 3:25 AM:
---------------------------------------------------------------------

You have to make sure that your own module actually creates a source JAR in the 
first place. Only then it will also be included in the shaded source JAR. This 
is easily forgotten and happened to me in the past, too. BTW, it is the same 
effect if you shade third-party dependencies and they do not publish source 
JARs on Maven Central or wherever you pull them from.

So just add something like this to the modules you wish to be included in the 
source JAR:

{code:xml}
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <version>3.2.1</version>
  <configuration>
    <!-- Re-create original source JAR in order to avoid re-shading already 
shaded JAR in non-clean builds -->
    <forceCreation>true</forceCreation>
  </configuration>
  <executions>
    <execution>
      <id>attach-sources</id>
      <phase>package</phase>
      <goals>
        <goal>jar-no-fork</goal>
      </goals>
    </execution>
  </executions>
</plugin>
{code}

The commented {{forceCreation}} option is only necessary if you shade in the 
same module where the sources are.


was (Author: kriegaex):
You have to make sure that your own module actually creates a source JAR in the 
first place. Only then it will also be included in the shaded source JAR. So 
just add something like this to the modules you wish to be included in the 
source JAR:

{code:xml}
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <version>3.2.1</version>
  <configuration>
    <!-- Re-create original source JAR in order to avoid re-shading already 
shaded JAR in non-clean builds -->
    <forceCreation>true</forceCreation>
  </configuration>
  <executions>
    <execution>
      <id>attach-sources</id>
      <phase>package</phase>
      <goals>
        <goal>jar-no-fork</goal>
      </goals>
    </execution>
  </executions>
</plugin>
{code}

The commented {{forceCreation}} option is only necessary if you shade in the 
same module where the sources are.

> Shaded sources out of sync with shaded jar.
> -------------------------------------------
>
>                 Key: MSHADE-217
>                 URL: https://issues.apache.org/jira/browse/MSHADE-217
>             Project: Maven Shade Plugin
>          Issue Type: Bug
>    Affects Versions: 2.4.3
>            Reporter: Zoltan Farkas
>            Priority: Major
>
> I am using the maven shade plugin to patch open source libraries. (fix 
> bugs...)
> this is the configuration I use:
> {noformat}
> <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>${project.groupId}:${project.artifactId}:${original.version}</include>
>                                     </includes>
>                                 </artifactSet>
>                                 
> <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
>                                 <createSourcesJar>true</createSourcesJar>
>                                 
> <shadeSourcesContent>true</shadeSourcesContent>
>                             </configuration>
>                         </execution>
>                     </executions>
>                 </plugin>
> {noformat}
> The java classes I have in my project, are correctly included in the shaded 
> jar and overwrite the dependency classes, however the source artifact 
> generated by the shade plugin does not include the sources from my project.
> Can this be improved so that source and class behaviour is consistent?
> is there a workarround?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to