-
Notifications
You must be signed in to change notification settings - Fork 52
Description
I have encountered a corner case which emerges when I generate my shaded uber jar. I have realized that shaded jar is not able to get service account credentials in a VM/GKE pod. When I decompiled the shaded jars, I have realized that the gcp metadata server path is prefixed with /com/google/cloud/spanner/jdbc/shaded .
As a solution I have changed pattern com to com. and I've applied similarly to io., org. and android.
Environment details
- spanner-jdbc-driver
- macos
- Java version: 8
- spanner-jdbc version(s): master
Steps to reproduce
- mvn package -Pshade -DskipTests
- cd target
- unzip google-cloud-spanner-jdbc-*-single-jar-with-dependencies.jar
- cd com/google/cloud/spanner/jdbc/shaded/com/google/auth/oauth2
- decompile ComputeEngineCredentials.class , you will see
public static String getServiceAccountsUrl() {
return getMetadataServerUrl(DefaultCredentialsProvider.DEFAULT) + "/com/google/cloud/spanner/jdbc/shaded/computeMetadata/v1/instance/service-accounts/?recursive=true";
}As you see above the metadata server path is prefixed by shaded address.
Solution
I have excluded the computeMetadata in pom.xml by changing the patterns.
<relocations>
<relocation>
<pattern>com.</pattern>
<shadedPattern>com.google.cloud.spanner.jdbc.shaded.com.</shadedPattern>
<excludes>
<exclude>com.google.cloud.spanner.**</exclude>
</excludes>
</relocation>
<relocation>
<pattern>android.</pattern>
<shadedPattern>com.google.cloud.spanner.jdbc.shaded.android.</shadedPattern>
</relocation>
<relocation>
<pattern>io.</pattern>
<shadedPattern>com.google.cloud.spanner.jdbc.shaded.io.</shadedPattern>
<excludes>
<exclude>io.grpc.netty.**</exclude>
</excludes>
</relocation>
<relocation>
<pattern>org.</pattern>
<shadedPattern>com.google.cloud.spanner.jdbc.shaded.org.</shadedPattern>
<excludes>
<exclude>org.conscrypt.**</exclude>
</excludes>
</relocation>
</relocations>Any additional information below
I have encountered this while trying to integrate cloud spanner to an old codebase.
Also I have realized that many libraries are dragged by shaded pom so when I add shaded jar as a dependency I have excluded everything:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-jdbc</artifactId>
<version>2.2.1-shaded</version>
<classifier>single-jar-with-dependencies</classifier>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>