Given maven shade plugin resource transformers, how can we create custom ones?
I've tried adding the shade plugin to my pom:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
</dependency>
And creating a class that implements ResourceTransformer. But when I run it, I get:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.4.1:shade (default) on project foo: Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:2.4.1:shade for parameter transformers: Cannot load implementation hint 'test.transformer.TestTransformer' -> [Help 1]
The transformer is on the same classpath as the project I'm running the build on, which, I'm guessing is the problem. Is there a way to add in an extension that brings in other transformers?
Aggregating classes/resources from several artifacts into one uber JAR is straight forward as long as there is no overlap. Otherwise, some kind of logic to merge resources from several JARs is required. This is where resource transformers kick in.
maven-shade-plugin : It packages all dependencies into one uber-jar. It can also be used to build an executable jar by specifying the main class. This plugin is particularly useful as it merges content of specific files instead of overwriting them by Relocating Classes.
You can avoid having it created by setting createDependencyReducedPom to false. e.g. If you turn it off, then the thing you build will still have all the merged-in dependencies listed as dependencies.
The dependency-reduced-pom. xml removes transitive dependencies which are already in your shaded jar. This prevents consumers from pulling them in twice.
See in the next section of the instructions:
test.transformer.TestTransformer
with the appropriate dependencies in its pom.xml
.pom.xml
in project.build.plugins.plugin[.id='maven-shade-plugin']
add the above maven project as a dependency.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With