diff --git a/java-bigquery/google-cloud-bigquery-jdbc/Dockerfile b/java-bigquery/google-cloud-bigquery-jdbc/Dockerfile
index f88cc5a4bc90..374a1c6a82fb 100644
--- a/java-bigquery/google-cloud-bigquery-jdbc/Dockerfile
+++ b/java-bigquery/google-cloud-bigquery-jdbc/Dockerfile
@@ -1,21 +1,24 @@
FROM gcr.io/cloud-devrel-public-resources/java11
-
+ARG BRANCH=main
ENV JDBC_DOCKER_ENV=true
-RUN apt-get update && apt-get install -y zip && rm -rf /var/lib/apt/lists/*
-
-RUN mkdir /tst
-COPY ./pom.xml /src/pom.xml
-COPY ./java.header /src/java.header
-COPY ./license-checks.xml /src/license-checks.xml
-COPY ./google-cloud-bigquery-jdbc/pom.xml /src/google-cloud-bigquery-jdbc/pom.xml
-COPY ./google-cloud-bigquery /src/google-cloud-bigquery
-COPY ./google-cloud-bigquery-bom /src/google-cloud-bigquery-bom
+# Changes to `pom.xml` will trigger re-sync
+COPY pom.xml /src/pom.xml
+# Doing it via single command, so layer contains only installed moduled vs full repo
+# Copy from local repo is taking forever. Doing via git clone will keep dependencies ~up to date.
+# It will fail on old branches forcing to sync to latest main branch.
+RUN bash -c " \
+ mkdir /git \
+ && cd /git \
+ && git clone -b ${BRANCH} --depth 1 --single-branch https://github.com/googleapis/google-cloud-java.git \
+ && cd /git/google-cloud-java \
+ && source .kokoro/common.sh \
+ && install_modules java-bigquery \
+ && rm -rf /git"
+# This will ensure all deps are present
WORKDIR /src
-RUN mvn install -DskipTests
-
-WORKDIR /src/google-cloud-bigquery-jdbc
+RUN mvn install
ENTRYPOINT []
diff --git a/java-bigquery/google-cloud-bigquery-jdbc/Makefile b/java-bigquery/google-cloud-bigquery-jdbc/Makefile
index db3a62e4637f..46ddae268aeb 100644
--- a/java-bigquery/google-cloud-bigquery-jdbc/Makefile
+++ b/java-bigquery/google-cloud-bigquery-jdbc/Makefile
@@ -1,6 +1,8 @@
+SHELL := /bin/bash # Default 'sh' doesn't support 'source'
+BUILD_BRANCH=main
CONTAINER_NAME=jdbc
PACKAGE_DESTINATION=$(PWD)/drivers
-SRC="$(PWD)/.."
+SRC="$(PWD)"
skipSurefire ?= true
# no indendation for ifndef\endif due to their evaluation before execution
@@ -10,7 +12,9 @@ ifndef GOOGLE_APPLICATION_CREDENTIALS
endif
install:
- mvn clean install
+ cd "$(PWD)/../.." && \
+ source ".kokoro/common.sh" && \
+ install_modules java-bigquery
clean:
mvn clean
@@ -77,7 +81,7 @@ generate-dependency-list:
$(CONTAINER_NAME) $(args)
docker-build:
- docker build -t $(CONTAINER_NAME) -f Dockerfile ..
+ docker build -t $(CONTAINER_NAME) -f Dockerfile --build-arg BRANCH=${BUILD_BRANCH} $(SRC)
docker-session:
$(MAKE) .docker-run args="bash"
diff --git a/java-bigquery/google-cloud-bigquery-jdbc/pom.xml b/java-bigquery/google-cloud-bigquery-jdbc/pom.xml
index 79c67ef38f6b..0c12456e7712 100644
--- a/java-bigquery/google-cloud-bigquery-jdbc/pom.xml
+++ b/java-bigquery/google-cloud-bigquery-jdbc/pom.xml
@@ -366,6 +366,10 @@
/mvn/test-target
+
+
+ true
+
\ No newline at end of file