Skip to content

Commit 3f9c7a0

Browse files
chore(hermetic-build): infer formatter version from java-shared-config property (#3711)
This ties the google-java-format.jar version to the one [declared in java-shared-config](https://github.com/googleapis/java-shared-config/blob/a315cf154ffb2dfd77ff7ce9892f8bb8a40ec7cc/java-shared-config/pom.xml#L31) The purpose is to later upgrade this version to avoid the old Guava dependency. I moved the download step to ggj-build so the final image only copies artifacts from "build related" stages. --------- Co-authored-by: Tomo Suzuki <[email protected]>
1 parent a961459 commit 3f9c7a0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

.cloudbuild/library_generation/library_generation.Dockerfile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ COPY . .
2323
ENV DOCKER_GAPIC_GENERATOR_VERSION="2.55.2-SNAPSHOT"
2424
# {x-version-update-end}
2525

26+
# Download the java formatter
27+
RUN mvn -pl gapic-generator-java-pom-parent help:evaluate -Dexpression='google-java-format.version' -q -DforceStdout > /java-formatter-version
28+
RUN cat /java-formatter-version
29+
RUN V=$(cat /java-formatter-version) && curl -o "/google-java-format.jar" "https://maven-central.storage-download.googleapis.com/maven2/com/google/googlejavaformat/google-java-format/${V}/google-java-format-${V}-all-deps.jar"
30+
31+
# Compile and install packages
2632
RUN mvn install -B -ntp -DskipTests -Dclirr.skip -Dcheckstyle.skip
2733
RUN cp "/root/.m2/repository/com/google/api/gapic-generator-java/${DOCKER_GAPIC_GENERATOR_VERSION}/gapic-generator-java-${DOCKER_GAPIC_GENERATOR_VERSION}.jar" \
2834
"./gapic-generator-java.jar"
@@ -52,7 +58,6 @@ FROM docker.io/library/python:3.13.2-alpine3.20@sha256:816feb29731cdee64b15b0ae9
5258
ARG OWLBOT_CLI_COMMITTISH=3a68a9c0de318784b3aefadcc502a6521b3f1bc5
5359
ARG PROTOC_VERSION=25.5
5460
ARG GRPC_VERSION=1.70.0
55-
ARG JAVA_FORMAT_VERSION=1.7
5661
ENV HOME=/home
5762
ENV OS_ARCHITECTURE="linux-x86_64"
5863

@@ -117,6 +122,11 @@ RUN owl-bot copy-code --version
117122
RUN chmod o+rx $(which owl-bot)
118123
RUN apk del -r npm && apk cache clean
119124

125+
# copy the Java formatter
126+
COPY --from=ggj-build "/google-java-format.jar" "${HOME}"/.library_generation/google-java-format.jar
127+
RUN chmod 755 "${HOME}"/.library_generation/google-java-format.jar
128+
ENV JAVA_FORMATTER_LOCATION="${HOME}/.library_generation/google-java-format.jar"
129+
120130
# Here we transfer gapic-generator-java from the previous stage.
121131
# Note that the destination is a well-known location that will be assumed at runtime
122132
# We hard-code the location string to avoid making it configurable (via ARG) as
@@ -125,12 +135,6 @@ COPY --from=ggj-build "/sdk-platform-java/gapic-generator-java.jar" "${HOME}/.li
125135
RUN chmod 755 "${HOME}/.library_generation/gapic-generator-java.jar"
126136
ENV GAPIC_GENERATOR_LOCATION="${HOME}/.library_generation/gapic-generator-java.jar"
127137

128-
# download the Java formatter
129-
ADD https://maven-central.storage-download.googleapis.com/maven2/com/google/googlejavaformat/google-java-format/${JAVA_FORMAT_VERSION}/google-java-format-${JAVA_FORMAT_VERSION}-all-deps.jar \
130-
"${HOME}"/.library_generation/google-java-format.jar
131-
RUN chmod 755 "${HOME}"/.library_generation/google-java-format.jar
132-
ENV JAVA_FORMATTER_LOCATION="${HOME}/.library_generation/google-java-format.jar"
133-
134138
# allow users to access the script folders
135139
RUN chmod -R o+rx /src
136140

0 commit comments

Comments
 (0)