-
Notifications
You must be signed in to change notification settings - Fork 35
Vendoring dependencies
The new version of the frameworks no longer vendor dependencies. If this causes conflicts with your existing versions, we strongly recommend that you update your dependencies whenever possible. In cases where it's not possible, you can vendor dependencies manually. Below are example project configurations for Maven and Gradle. They are meant to be used as subproject builds and then referenced by your application code.
The essential steps are as follows:
- Create a subproject with the following
build.gradle
. - Add the subproject to your
settings.gradle
. - Update your dependency to point to your shadowed subproject:
compile project(path: 'yournewsubproject', configuration: 'shadow')
Below is a sample build.gradle
. We recommend you only vendor the conflicting dependencies, rather than all of them, as shown below. Simply remove the relocate
lines which contain non-conflicting dependencies.
plugins {
id 'com.github.johnrengelman.shadow' version '1.2.3'
}
configurations {
include
compile.extendsFrom include
}
jar {
from {
configurations.include.collect { it.isDirectory() ? it : zipTree(it) }
}
}
def repackagedDir = 'com.google.api.server.spi.repackaged'
shadowJar {
relocate 'org.apache', "${repackagedDir}.org.apache"
relocate 'org.yaml', "${repackagedDir}.org.yaml"
relocate 'org.joda', "${repackagedDir}.org.joda"
relocate 'com.fasterxml', "${repackagedDir}.com.fasterxml"
relocate 'io.swagger', "${repackagedDir}.io.swagger"
relocate 'com.google.common', "${repackagedDir}.com.google.common"
relocate 'com.google.api.client', "${repackagedDir}.com.google.api.client"
relocate 'org.slf4j', "${repackagedDir}.org.slf4j"
dependencies {
exclude(dependency('com.google.appengine:appengine-api-1.0-sdk:.*'))
exclude(dependency('javax.servlet:servlet-api:.*'))
}
}
dependencies {
include 'com.google.endpoints:endpoints-framework:2.0.0-beta.7'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.40'
compile 'javax.servlet:servlet-api:2.5'
}
The essential steps are as follows:
- Create a
pom.xml
with your shading configuration. - Run
mvn clean install
in the directory with thepom.xml
. - Add the shaded dependency to your application.
Below is a sample pom.xml
. We recommend you only vendor the conflicting dependencies, rather than all of them, as shown below. Simply remove the relocation
lines which contain non-conflicting dependencies.
<project>
<modelVersion>4.0.0</modelVersion>
<version>1.0-SNAPSHOT</version>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework-shaded</artifactId>
<properties>
<repackaged.dir>com.google.api.server.spi.repackaged</repackaged.dir>
</properties>
<dependencies>
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework</artifactId>
<version>2.0.0-beta.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>com.google.appengine:appengine-api-1.0-sdk</exclude>
<exclude>javax.servlet:servlet-api</exclude>
</excludes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.apache</pattern>
<shadedPattern>${repackaged.dir}.org.apache</shadedPattern>
</relocation>
<relocation>
<pattern>org.yaml</pattern>
<shadedPattern>${repackaged.dir}.org.yaml</shadedPattern>
</relocation>
<relocation>
<pattern>org.joda</pattern>
<shadedPattern>${repackaged.dir}.org.joda</shadedPattern>
</relocation>
<relocation>
<pattern>com.fasterxml</pattern>
<shadedPattern>${repackaged.dir}.com.fasterxml</shadedPattern>
</relocation>
<relocation>
<pattern>io.swagger</pattern>
<shadedPattern>${repackaged.dir}.io.swagger</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.common</pattern>
<shadedPattern>${repackaged.dir}.com.google.common</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.api.client</pattern>
<shadedPattern>${repackaged.dir}.com.google.api.client</shadedPattern>
</relocation>
<relocation>
<pattern>org.slf4j</pattern>
<shadedPattern>${repackaged.dir}.org.slf4j</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>