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