Read java versions for uploading java_tools from BUILD file

This avoids having to keep the version list in sync manually.
Currently, the script fails since there are not test targets matching versions 15,16 after https://github.com/bazelbuild/bazel/pull/14573

PiperOrigin-RevId: 440855181
diff --git a/src/upload_all_java_tools.sh b/src/upload_all_java_tools.sh
index 0da2991..fc6e35f 100755
--- a/src/upload_all_java_tools.sh
+++ b/src/upload_all_java_tools.sh
@@ -73,7 +73,8 @@
 # Skip for now, as the test is broken on Windows.
 # See https://github.com/bazelbuild/bazel/issues/12244 for details
 if [[ "$platform" != "windows" ]]; then
-    for java_version in 11 15 16 17; do
+    JAVA_VERSIONS=`cat src/test/shell/bazel/BUILD | grep '^JAVA_VERSIONS = ' | sed -e 's/JAVA_VERSIONS = //' | sed -e 's/["(),]//g'`
+    for java_version in $JAVA_VERSIONS; do
         bazel test --verbose_failures --test_output=all --nocache_test_results \
             //src/test/shell/bazel:bazel_java_test_local_java_tools_jdk${java_version} \
             --define=LOCAL_JAVA_TOOLS_ZIP_URL="${file_url}" \