Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven shade plugin custom transformer

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?

like image 297
javamonkey79 Avatar asked Nov 13 '15 06:11

javamonkey79


People also ask

What is transformer in maven shade plugin?

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.

Why do we need maven shade plugin?

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.

How do I remove dependency reduced POM?

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.

What is dependency reduced POM XML?

The dependency-reduced-pom. xml removes transitive dependencies which are already in your shaded jar. This prevents consumers from pulling them in twice.


1 Answers

See in the next section of the instructions:

  • create a maven project that contains test.transformer.TestTransformer with the appropriate dependencies in its pom.xml.
  • in the original project project's pom.xml in project.build.plugins.plugin[.id='maven-shade-plugin'] add the above maven project as a dependency.
like image 137
Tassos Bassoukos Avatar answered Sep 17 '22 23:09

Tassos Bassoukos