From 5af4e3b35f93e8a82ae81c78595d293750110497 Mon Sep 17 00:00:00 2001 From: Oli Date: Thu, 12 May 2022 12:18:19 -0700 Subject: [PATCH] Fix robolectric test runtime failures due to large classpath w/ 1.5k+ entries --- .../lib/bazel/rules/java/java_stub_template.txt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt index 2aabedcdf942f2..ead96f3941e116 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt @@ -363,8 +363,18 @@ if [ -z "$CLASSPATH_LIMIT" ]; then fi if (("${#CLASSPATH}" > ${CLASSPATH_LIMIT})); then - export JACOCO_IS_JAR_WRAPPED=1 - create_and_run_classpath_jar + java_ver=$(JAVABIN --version 2>&1) | head -1 + if [[ "$java_ver" =~ [^.0-9]1[.][1-8] ]]; then + # Arguments file is not supported by Java SDK version 1.8 and earlier, use classpath jar as fallback + export JACOCO_IS_JAR_WRAPPED=1 + create_and_run_classpath_jar + else + # Using argument file is more robust and efficient than Classpath jar + ARGS_FILE="$(mktemp -t XXXXXXXX.args)" + echo "-cp "$CLASSPATH >> $ARGS_FILE + exec $JAVABIN @$ARGS_FILE "${ARGS[@]}" + rm $ARGS_FILE + fi else exec $JAVABIN -classpath $CLASSPATH "${ARGS[@]}" fi