maven-shade-plugin
maven-shade-plugin copied to clipboard
[MSHADE-217] Shaded sources out of sync with shaded jar.
Zoltan Farkas opened MSHADE-217 and commented
I am using the maven shade plugin to patch open source libraries. (fix bugs...)
this is the configuration I use:
<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>
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?
Affects: 2.4.3
1 votes, 3 watchers
Matthieu Ghilain commented
I have exactly the same problem here with version 2.4.3. Has anyone been looking into that issue?
Alexander Kriegisch commented
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:
<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>
The commented forceCreation option is only necessary if you shade in the same module where the sources are.