Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 161 additions & 14 deletions java-bigquery/google-cloud-bigquery-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.2</version> <!-- Use the latest version -->
<version>3.6.1</version>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -97,6 +97,8 @@
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createSourcesJar>true</createSourcesJar>
<shadeSourcesContent>true</shadeSourcesContent>
<shadedClassifierName>all</shadedClassifierName> <!-- Any name that makes sense -->
<createDependencyReducedPom>false</createDependencyReducedPom>
<archive>
Expand All @@ -115,23 +117,164 @@
</transformers>
<relocations>
<relocation>
<pattern>com</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com</shadedPattern>
<excludes>
<exclude>com.google.cloud.bigquery.**</exclude>
<exclude>com.google.api.services.bigquery.**</exclude>
</excludes>
<pattern>com.google.api.client</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.api.client</shadedPattern>
</relocation>
<relocation>
<pattern>org</pattern>
<shadedPattern>com.google.bqjdbc.shaded.org</shadedPattern>
<excludes>
<exclude>org.conscrypt.*</exclude>
</excludes>
<pattern>com.google.api.core</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.api.core</shadedPattern>
</relocation>
<relocation>
<pattern>io</pattern>
<shadedPattern>com.google.bqjdbc.shaded.io</shadedPattern>
<pattern>com.google.api.gax</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.api.gax</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.api.pathtemplate</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.api.pathtemplate</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.api.resourcenames</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.api.resourcenames</shadedPattern>
</relocation>
Comment on lines +120 to +138
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Relocating individual sub-packages of com.google.api is fragile and misses classes in the base package (e.g., com.google.api.Annotations). It is more robust to relocate the entire com.google.api package while excluding the BigQuery-specific services that should remain unshaded. This ensures all transitive dependencies within the API surface are correctly relocated and avoids potential binary incompatibilities.

                    <relocation>
                      <pattern>com.google.api</pattern>
                      <shadedPattern>com.google.bqjdbc.shaded.com.google.api</shadedPattern>
                      <excludes>
                        <exclude>com.google.api.services.bigquery.**</exclude>
                      </excludes>
                    </relocation>

<relocation>
<pattern>com.google.apps</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.apps</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.auth</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.auth</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.auto</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.auto</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.cloud.audit</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.cloud.audit</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.cloud.http</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.cloud.http</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.cloud.location</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.cloud.location</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.cloud.spi</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.cloud.spi</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.cloud.testing</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.cloud.testing</shadedPattern>
</relocation>
<relocation>
Comment on lines +152 to +171
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the com.google.api relocation, targeting only specific sub-packages of com.google.cloud misses important base classes like com.google.cloud.ServiceOptions. Relocating the parent package with an explicit exclusion for BigQuery is a safer and more maintainable approach that prevents potential classpath conflicts with the host application's version of google-cloud-core.

                    <relocation>
                      <pattern>com.google.cloud</pattern>
                      <shadedPattern>com.google.bqjdbc.shaded.com.google.cloud</shadedPattern>
                      <excludes>
                        <exclude>com.google.cloud.bigquery.**</exclude>
                      </excludes>
                    </relocation>

<pattern>com.google.common</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.common</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.errorprone</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.errorprone</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.flatbuffers</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.flatbuffers</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.geo</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.geo</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.gson</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.gson</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.iam</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.iam</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.j2objc</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.j2objc</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.logging</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.logging</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.longrunning</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.longrunning</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.protobuf</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.protobuf</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.rpc</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.rpc</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.shopping</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.shopping</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.thirdparty</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.thirdparty</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.type</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.type</shadedPattern>
</relocation>
<relocation>
Comment on lines 119 to +227
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current approach of manually listing every com.google.* sub-package is fragile and difficult to maintain. It also misses several critical base packages such as com.google.cloud (which contains core classes like ServiceOptions) and com.google.api, which can lead to runtime classpath conflicts if users have different versions of these core libraries in their environment.

Consolidating these into a single com.google relocation pattern is more robust, ensures all current and future sub-packages are covered, and still avoids the computeMetadata string replacement bug since computeMetadata does not start with com.google.

Suggested change
<relocation>
<pattern>com</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com</shadedPattern>
<excludes>
<exclude>com.google.cloud.bigquery.**</exclude>
<exclude>com.google.api.services.bigquery.**</exclude>
</excludes>
<pattern>com.google.api.client</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.api.client</shadedPattern>
</relocation>
<relocation>
<pattern>org</pattern>
<shadedPattern>com.google.bqjdbc.shaded.org</shadedPattern>
<excludes>
<exclude>org.conscrypt.*</exclude>
</excludes>
<pattern>com.google.api.core</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.api.core</shadedPattern>
</relocation>
<relocation>
<pattern>io</pattern>
<shadedPattern>com.google.bqjdbc.shaded.io</shadedPattern>
<pattern>com.google.api.gax</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.api.gax</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.api.pathtemplate</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.api.pathtemplate</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.api.resourcenames</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.api.resourcenames</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.apps</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.apps</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.auth</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.auth</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.auto</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.auto</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.cloud.audit</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.cloud.audit</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.cloud.http</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.cloud.http</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.cloud.location</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.cloud.location</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.cloud.spi</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.cloud.spi</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.cloud.testing</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.cloud.testing</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.common</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.common</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.errorprone</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.errorprone</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.flatbuffers</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.flatbuffers</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.geo</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.geo</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.gson</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.gson</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.iam</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.iam</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.j2objc</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.j2objc</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.logging</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.logging</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.longrunning</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.longrunning</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.protobuf</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.protobuf</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.rpc</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.rpc</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.shopping</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.shopping</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.thirdparty</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.thirdparty</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.type</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google.type</shadedPattern>
</relocation>
<relocation>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.google</shadedPattern>
<excludes>
<exclude>com.google.cloud.bigquery.**</exclude>
<exclude>com.google.api.services.bigquery.**</exclude>
</excludes>
</relocation>

<pattern>com.fasterxml.jackson</pattern>
<shadedPattern>com.google.bqjdbc.shaded.com.fasterxml.jackson</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache</pattern>
<shadedPattern>com.google.bqjdbc.shaded.org.apache</shadedPattern>
</relocation>
<relocation>
<pattern>org.checkerframework</pattern>
<shadedPattern>com.google.bqjdbc.shaded.org.checkerframework</shadedPattern>
</relocation>
<relocation>
<pattern>org.codehaus</pattern>
<shadedPattern>com.google.bqjdbc.shaded.org.codehaus</shadedPattern>
</relocation>
<relocation>
<pattern>org.jspecify</pattern>
<shadedPattern>com.google.bqjdbc.shaded.org.jspecify</shadedPattern>
</relocation>
<relocation>
<pattern>org.threeten</pattern>
<shadedPattern>com.google.bqjdbc.shaded.org.threeten</shadedPattern>
</relocation>
<relocation>
<pattern>org.json</pattern>
<shadedPattern>com.google.bqjdbc.shaded.org.json</shadedPattern>
</relocation>
<relocation>
<pattern>org.slf4j</pattern>
<shadedPattern>com.google.bqjdbc.shaded.org.slf4j</shadedPattern>
</relocation>
Comment on lines +256 to +258
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Shading org.slf4j is generally discouraged for libraries and JDBC drivers as it breaks the logging integration with the host application. By relocating the SLF4J facade, the driver's internal logs will not be captured by the application's logging configuration (e.g., Logback or Log4j2). Unless there is a specific version conflict that cannot be resolved otherwise, it is better to leave org.slf4j unshaded to allow for proper observability.

<relocation>
<pattern>io.grpc</pattern>
<shadedPattern>com.google.bqjdbc.shaded.io.grpc</shadedPattern>
</relocation>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>com.google.bqjdbc.shaded.io.netty</shadedPattern>
</relocation>
<relocation>
<pattern>io.opencensus</pattern>
<shadedPattern>com.google.bqjdbc.shaded.io.opencensus</shadedPattern>
</relocation>
<relocation>
<pattern>io.opentelemetry</pattern>
<shadedPattern>com.google.bqjdbc.shaded.io.opentelemetry</shadedPattern>
</relocation>
<relocation>
<pattern>io.perfmark</pattern>
<shadedPattern>com.google.bqjdbc.shaded.io.perfmark</shadedPattern>
</relocation>
</relocations>
<filters>
Expand All @@ -146,6 +289,10 @@
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>arrow-git.properties</exclude>
<exclude>module-info.class</exclude>
<exclude>META-INF/versions/*/module-info.class</exclude>
<exclude>module-info.java</exclude>
<exclude>META-INF/versions/*/module-info.java</exclude>
</excludes>
</filter>
</filters>
Expand Down
Loading