I cannot figure out why the creation of a snap (geogebra-discovery) fails on the automated build server:
Downloading https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
Exception in thread "main" java.net.UnknownHostException: services.gradle.org
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:220)
I guess Gradle wants to connect to some servers, maybe services.gradle.org, but this seems blocked. I use my own build machinery to build the application, so I donât use the gradle plugin.
Ancient post I know, but in case it helps anyone else (and as the author of that linked Stackoverflow question which Iâve since updated) - use -Djava.net.useSystemProxies=true as an additional option to Gradle.
Thanks! Finally I learned that if the gradle plugin is used, things just work (connection to outside is allowed). Otherwise, connections to Gradle repositories are blocked.
Just bear in mind that the Gradle plugin is sadly not compatible with the newer corexx bases. I used to use that Gradle plugin, but had to shift away from it (and thus do some more investigating / debugging to work out what was going on.)
Good news though is with the above option you can avoid the plugin entirely if you wish
Where youâd substitute with the Launchpad ones (reason I havenât here is because I donât have time to check how thatâs formatted, you might need to manipulate the string).
You can see how the old plugin used to do it, in Python, here:
Functionally itâs just translating that into Bash; except rather than appending to the build command, itâs likely easier to just issue as a separate command/config line.
By the looks of that plugin, I expect the format is 1.2.3.4:8080, I.E ip:port, where the cut command could split the two easily, e.g:
Figure out how to use it with the Canonical build environment from within the snap.
It ended up me having to write a supporting script to dig out the settings.
#!/bin/sh
get_proxy_options() {
proxy_options=""
for var in http https; do
proxy=$(printenv "${var}_proxy")
if [ -n "$proxy" ]; then
# Remove trailing /
proxy=$(echo "$proxy" | sed 's|/$||')
# Extract hostname and port using POSIX-compatible tools
proto="$(echo $proxy | sed -e's,^\(.*://\).*,\1,g')"
url=$(echo $proxy | sed -e s,$proto,,g)
hostname=$(echo $url | cut -d: -f1)
port=$(echo $url | cut -d: -f2)
proxy_options="${proxy_options} -D${var}.proxyHost=${hostname}"
if [ -n "$port" ]; then
proxy_options="${proxy_options} -D${var}.proxyPort=${port}"
fi
fi
done
echo "$proxy_options"
}
# Call the function and store the result
proxy_options=$(get_proxy_options)
# Print the proxy options
echo "$proxy_options"
Then finally use it with gradlew as below:
override-build: |
echo "BEGIN BUILD OF BESU - gradlew in override-build"
echo "Extracting potential https_proxy and/pr http_proxy as needed when building with Canonical buildfarm"
PROXY_OPTS=$($SNAPCRAFT_STAGE/utils/getproxy.sh)
GRADLE_OPTS="-Djava.net.useSystemProxies=true $PROXY_OPTS" ./gradlew --no-daemon installDist
echo "COMPLETED BUILD OF BESU - gradlew"
This was a nightmare and took me about two full days to mess with since it takes forever to test every small change.