During gradle.bat execution gradle-wrapper.jar returns java.net.UnknownHostException downloading distribution even with proxy settings

Overall goal is to implement an Azure Devops Server 2019 CI build. When running:
Ionic Cordova build android --prod --release
it eventually invokes gradle.bat which ultimately fails when calling
“%JAVA_EXE%” %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% “-Dorg.gradle.appname=%APP_BASE_NAME%” -classpath “%CLASSPATH%” org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

with the following output:
Downloading https://services.gradle.org/distributions/gradle-6.5-all.zip

Exception in thread “main” java.net.UnknownHostException: services.gradle.org
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:200)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1175)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
at org.gradle.wrapper.Download.downloadInternal(Download.java:83)
at org.gradle.wrapper.Download.download(Download.java:66)
at org.gradle.wrapper.Install$1.call(Install.java:68)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)

I can reproduce the above error from a CMD window on the Windows Server 2019 build agent VM logged in as the build identity with the command:
“C:\Program Files\Java\jdk1.8.0_181/bin/java.exe” “-Xmx64m” “-Xms64m” “-Dorg.gradle.appname=gradlew” -classpath “D:\Agent_1_work\2\s\platforms\android\gradle\wrapper\gradle-wrapper.jar” org.gradle.wrapper.GradleWrapperMain

Using 1.2.3.4 in my examples below as the proxy IP address and 80 as the port (not the real values) I have tried setting the http.proxyHost, https.proxyHost, http.proxyPort, and https.proxyPort values:

  • By setting JAVA_OPTS as “-Dhttp.proxyHost=1.2.3.4 -Dhttps.proxyHost=1.2.3.4 -Dhttp.proxyPort=80 -Dhttps.proxyPort=80”
  • By setting GRADLE_OPTS to the same value as above
  • By including the above as command line arguments after java.exe
  • By adding the above as systemProp.http.proxyHost=1.2.3.4 (etc.) lines in a gradle.properties file in the D:\Agent_1_work\2\s\platforms\android folder
  • By adding the same systemProp settings to the D:\Agent_1_work\2\s\platforms\android\gradle\wrapper\gradle-wrapper.properties file that specifies distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip (I know it’s at least parsing that file since changes to that URL are reflected in the log output)
  • I’ve tried most or all of the above with also adding proxyUser and proxyPassword settings (even added nonProxyHosts=localhost just to make sure it wasn’t defaulting to something really odd if unset)
  • I tried setting systemProp.http.auth.ntlm.domain, systemProp.https.auth.ntlm.domain in gradle.properties/gradle-wrapper.properties files instead of specifying the domain in the user name too.

All of those attempts gave the same error.

I did a simple test of using the same CMD window and executed:
bitsadmin /transfer TestGradleAccess /download /priority normal https://services.gradle.org/distributions/gradle-6.5-all.zip D:\Temp\gradle-6.5-all.zip
That downloads the .zip file just fine.

I tried setting my machine proxy settings manually to the proxy and port above and was able to access services.gradle.org with a browser, and confirmed that if I set a nonsense proxy I lose access to that page (so I know the proxy and port are correct).

I could store that file locally (pull it down from an internal nuget feed or something silly and save it in the build environment somewhere) and have the build just use that by specifying file:/// … (already verified that works) but I’d like the build to continue to work without unexpected pain if versions are updated (it could become an example for more builds later, so ideally it should be a pattern we’d want to copy). I’ve mostly run out of ideas to try and can’t seem to get any deeper details of what the error is.