Hi Matt and Michael,

Matt Benson wrote:
> In my experience you must relocate each individual package; simply
> relocating org.apache.http is not sufficient.

In my experience, the maven-shade-plugin will process subpackages which
match the given patterns. Here is a working example that shades all of
Jython's dependencies:

https://github.com/scijava/jython-shaded/blob/jython-shaded-2.5.3/deps/pom.xml#L56-L93

Regards,
Curtis

On Thu, Jun 25, 2015 at 7:25 AM, Matt Benson <gudnabr...@gmail.com> wrote:

> In my experience you must relocate each individual package; simply
> relocating org.apache.http is not sufficient.
>
> Matt
> On Jun 25, 2015 6:11 AM, "mmccar...@tribloom.com" <mmccar...@tribloom.com>
> wrote:
>
> > I have been attempting to "shade"[1] the AWS Java SDK[2] version 1.10.1,
> > specifically the S3 SDK, to relocate the Apache HTTPCompontents[3]
> > libraries. I am attempting to do this in order to resolve a dependency
> > conflict with another more complicated project which is also dependent on
> > an older version of HTTPComponents. So far I have been unsuccessful and
> > can't determine if it is misconfiguration or an issue with the plugin. I
> > hope it is the former.
> >
> > First I added a Maven Shade configuration to the aws-java-sdk-core
> pom.xml:
> > <plugin>
> >    <groupId>org.apache.maven.plugins</groupId>
> >    <artifactId>maven-shade-plugin</artifactId>
> >    <version>2.4</version>
> >    <configuration>
> >       <artifactSet>
> >          <includes>
> >             <include>com.amazonaws:*</include>
> > <include>org.apache.httpcomponents:*</include>
> >          </includes>
> >       </artifactSet>
> >       <relocations>
> >          <relocation>
> >             <pattern>org.apache.http</pattern>
> > <shadedPattern>org.shaded.http</shadedPattern>
> >          </relocation>
> >       </relocations>
> >    </configuration>
> >    <executions>
> >       <execution>
> >          <phase>package</phase>
> >          <goals>
> >             <goal>shade</goal>
> >          </goals>
> >       </execution>
> >    </executions>
> > </plugin>
> >
> > This seems to work fine and produces a jar that seems to be as expected
> > when I build the project using "mvn clean install -Dgpg.skip=true
> > -DskipTests=true", although I haven't tested it. Second, I modify the
> > aws-java-sdk-s3 pom.xml as follows:
> > <plugin>
> >    <groupId>org.apache.maven.plugins</groupId>
> >    <artifactId>maven-shade-plugin</artifactId>
> >    <version>2.4</version>
> >    <configuration>
> >       <shadeSourcesContent>true</shadeSourcesContent>
> >       <createSourcesJar>true</createSourcesJar>
> >       <artifactSet>
> >          <includes>
> >             <include>com.amazonaws:*</include>
> > <include>org.apache.httpcomponents:*</include>
> >          </includes>
> >       </artifactSet>
> >       <relocations>
> >          <relocation>
> >             <pattern>org.apache.http</pattern>
> > <shadedPattern>org.shaded.http</shadedPattern>
> >          </relocation>
> >       </relocations>
> >    </configuration>
> >    <executions>
> >       <execution>
> >          <phase>package</phase>
> >          <goals>
> >             <goal>shade</goal>
> >          </goals>
> >       </execution>
> >    </executions>
> > </plugin>
> >
> > By itself this produces build errors like this:
> > [ERROR]
> >
> \dev\CSJ\aws\aws-sdk-java-1.10.1\aws-java-sdk-s3\src\main\java\com\amazonaws\services\s3\model\S3ObjectInputStream.java:[20,29]
> > error: package org.apache.http.client does not exist
> >
> > So I added an explicit dependency on HTTPComponents to the S3 pom.xml:
> > <dependency>
> >    <groupId>org.apache.httpcomponents</groupId>
> >    <artifactId>httpclient</artifactId>
> >    <version>4.3.6</version>
> > </dependency>
> >
> > When I build I get only one error:
> > [ERROR]
> >
> \dev\CSJ\aws\aws-sdk-java-1.10.1\aws-java-sdk-s3\src\main\java\com\amazonaws\services\s3\internal\S3ObjectResponseHandler.java:[54,26]
> > error: no suitable constructor found for
> >
> S3ObjectInputStream(InputStream,org.shaded.http.client.methods.HttpRequestBase)
> >
> > It appears to me that the "shading" is not actually relocating the
> > http.client.methods.HttpRequestBase argument to the S3ObjectInputStream
> > class within the code. Running javap confirms this:
> > $ javap
> > target/classes/com/amazonaws/services/s3/model/S3ObjectInputStream.class
> > Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
> > Compiled from "S3ObjectInputStream.java"
> > public class com.amazonaws.services.s3.model.S3ObjectInputStream extends
> > com.amazonaws.internal.SdkFilterInputStream {
> >   public
> > com.amazonaws.services.s3.model.S3ObjectInputStream(java.io.InputStream,
> > org.apache.http.client.methods.HttpRequestBase);
> >   public
> > com.amazonaws.services.s3.model.S3ObjectInputStream(java.io.InputStream,
> > org.apache.http.client.methods.HttpRequestBase, boolean);
> >   public void abort();
> >   public org.apache.http.client.methods.HttpRequestBase getHttpRequest();
> >   public int available() throws java.io.IOException;
> > }
> >
> > Can anyone point out if my configuration is wrong, my methodology is
> > wrong, or the Maven Shade plugin is actually not behaving as expected?
> >
> > [1] http://maven.apache.org/plugins/maven-shade-plugin/index.html
> > [2] https://github.com/aws/aws-sdk-java
> > [3] https://hc.apache.org/
> >
> > Thanks,
> > --
> > Michael
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
> > For additional commands, e-mail: users-h...@maven.apache.org
> >
> >
>

Reply via email to