How to relocate dependency classes using maven-shade-plugin?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to relocate dependency classes using maven-shade-plugin?

David Hoffer
I have a single module Maven build where one of the dependences has well
over 200 transitive dependencies.  These transitive dependencies are
incompatible with the rest of my application.

I would like to use the maven-shade-plugin to create a shaded jar uber jar
that contains all of these dependencies that all have been relocated to a
custom package name.  Then I need the Maven build to include this new
shaded dependency instead of the prior/regular one.

How can I configure the maven-shade-plugin to do this?  So far I have not
gotten it to process dependencies at all only other project code.  I want
it to start relocating at the top level dependency that I specify and have
it include all transitive ones from there.

Any pointers, examples are greatly appreciated.

-Dave
Reply | Threaded
Open this post in threaded view
|

Re: How to relocate dependency classes using maven-shade-plugin?

Alexander Kriegisch-2
Hi Dave.

I recommend to start with a simple stand-alone project in order to find out how Maven Shade works. It can be quite tricks for beginners otherwise. Create a POM, add a dependency - any dependency, some open source library maybe - and then try shading and relocating it with Maven Shade. This should work for both the binaries and (optionally) also for the sources. Both uber JARs (binaries and sources) should be pulled including transitive dependencies and you can even relocate the source code. Inspect the resulting JARs and play with filtering options (for both dependency names and files/directories) as well as with relocation. Then if you have an MCVE [1] and a concrete problem, feel free to report back here. Until then use [2] as a reference, especially [3] and [4]. Start simple and step by step, then increase the level of difficulty. Don't try to use 7 options at one, see what each of them does.

[1] https://stackoverflow.com/help/mcve
[2] https://maven.apache.org/plugins/maven-shade-plugin/
[3] https://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html
[4] https://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html

--
Alexander Kriegisch
https://scrum-master.de


David Hoffer schrieb am 31.03.2021 22:54 (GMT +07:00):

> I have a single module Maven build where one of the dependences has
> well over 200 transitive dependencies. These transitive dependencies
> are incompatible with the rest of my application.
>
> I would like to use the maven-shade-plugin to create a shaded jar uber
> jar that contains all of these dependencies that all have been
> relocated to a custom package name. Then I need the Maven build to
> include this new shaded dependency instead of the prior/regular one.
>
> How can I configure the maven-shade-plugin to do this? So far I have
> not gotten it to process dependencies at all only other project code.
> I want it to start relocating at the top level dependency that I
> specify and have it include all transitive ones from there.
>
> Any pointers, examples are greatly appreciated.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to relocate dependency classes using maven-shade-plugin?

Alexander Kriegisch-2
> Hi Dave.
>
> I recommend to start with a simple stand-alone project in order to
> find out how Maven Shade works. It can be quite tricks for beginners
> otherwise. Create a

Typo: I mean "tricky", of course.

> POM, add a dependency - any dependency, some open source library maybe
> - and then try shading and relocating it with Maven Shade. This should
> work for both the binaries and (optionally) also for the sources. Both
> uber JARs (binaries and sources) should be pulled including transitive
> dependencies and you can even relocate the source code. Inspect the
> resulting JARs and play with filtering options (for both dependency
> names and files/directories) as well as with relocation. Then if you
> have an MCVE [1] and a concrete problem, feel free to report back
> here. Until then use [2] as a reference, especially [3] and [4]. Start
> simple and step by step, then increase the level of difficulty. Don't
> try to use 7 options at one, see what each of them does.
>
> [1] https://stackoverflow.com/help/mcve
> [2] https://maven.apache.org/plugins/maven-shade-plugin/
> [3] https://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html
> [4] https://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html
>
> --
> Alexander Kriegisch
> https://scrum-master.de
>
>
> David Hoffer schrieb am 31.03.2021 22:54 (GMT +07:00):
>
>> I have a single module Maven build where one of the dependences has
>> well over 200 transitive dependencies. These transitive dependencies
>> are incompatible with the rest of my application.
>>
>> I would like to use the maven-shade-plugin to create a shaded jar
>> uber jar that contains all of these dependencies that all have been
>> relocated to a custom package name. Then I need the Maven build to
>> include this new shaded dependency instead of the prior/regular one.
>>
>> How can I configure the maven-shade-plugin to do this? So far I have
>> not gotten it to process dependencies at all only other project code.
>> I want it to start relocating at the top level dependency that I
>> specify and have it include all transitive ones from there.
>>
>> Any pointers, examples are greatly appreciated.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]