From af7cc0f2cf8786cecf97b07fc352b12ba9012c0d Mon Sep 17 00:00:00 2001 From: Michael Basnight Date: Fri, 1 Sep 2017 08:57:16 -0500 Subject: [PATCH] Add a shading example to the rest client docs This adds a maven and gradle example for shading as well as the caveat about shading and commons logging. Ref #26449 --- docs/java-rest/low-level/usage.asciidoc | 76 +++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/docs/java-rest/low-level/usage.asciidoc b/docs/java-rest/low-level/usage.asciidoc index 7dbec495b28..d39fab38dda 100644 --- a/docs/java-rest/low-level/usage.asciidoc +++ b/docs/java-rest/low-level/usage.asciidoc @@ -65,6 +65,82 @@ http://hc.apache.org/httpcomponents-asyncclient-dev/[Apache Http Async Client] - commons-codec:commons-codec - commons-logging:commons-logging +[[java-rest-low-usage-shading]] +=== Shading + +In order to avoid version conflicts, the dependencies can be shaded and packaged +within the client in a single JAR file (sometimes called an "uber JAR" or "fat +JAR"). Shading a dependency consists of taking its content (resources files and +Java class files) and renaming some of its packages before putting them in the +same JAR file as the low-level Java REST client. Shading a JAR can be +accomplished by 3rd-party plugins for Gradle and Maven. + +Be advised that shading a JAR also has implications. Shading the Commons Logging +layer, for instance, means that 3rd-party logging backends need to be shaded as +well. + +[[java-rest-low-usage-shading-maven]] +==== Maven configuration + +Here is a configuration using the Maven +https://maven.apache.org/plugins/maven-shade-plugin/index.html[Shade] +plugin. Add the following to your `pom.xml` file: + +["source","xml",subs="attributes"] +-------------------------------------------------- + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + package + shade + + + + org.apache.http + hidden.org.apache.http + + + org.apache.logging + hidden.org.apache.logging + + + org.apache.commons.codec + hidden.org.apache.commons.codec + + + org.apache.commons.logging + hidden.org.apache.commons.logging + + + + + + + + +-------------------------------------------------- + +[[java-rest-low-usage-shading-gradle]] +==== Gradle configuration + +Here is a configuration using the Gradle +https://github.com/johnrengelman/shadow[ShadowJar] plugin. Add the following to +your `build.gradle` file: + +["source","groovy",subs="attributes"] +-------------------------------------------------- +shadowJar { + relocate 'org.apache.http', 'hidden.org.apache.http' + relocate 'org.apache.logging', 'hidden.org.apache.logging' + relocate 'org.apache.commons.codec', 'hidden.org.apache.commons.codec' + relocate 'org.apache.commons.logging', 'hidden.org.apache.commons.logging' +} +-------------------------------------------------- [[java-rest-low-usage-initialization]] === Initialization