Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
Last active December 9, 2022 04:44
Show Gist options
  • Save sandipchitale/3134e67b06291dfaa49b8346cceaf68f to your computer and use it in GitHub Desktop.
Save sandipchitale/3134e67b06291dfaa49b8346cceaf68f to your computer and use it in GitHub Desktop.
Configure http proxy #powershell #proxy
task generateHttpProxy() {
doFirst {
println "Paste the above sysprops to your gradle.properties in your project or ${project.gradle.gradleUserHomeDir}${File.separator}gradle.properties"
}
}
defaultTasks 'generateHttpProxy'
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
// https://docs.gradle.org/current/userguide/build_environment.html#sec:accessing_the_web_via_a_proxy
if (DefaultNativePlatform.getCurrentOperatingSystem().isWindows()) {
String proxyEnabled = ['reg', 'query', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', '/v', 'ProxyEnable'].execute().text
proxyEnabled.eachLine {
if (it.trim().startsWith('ProxyEnable')) {
if ('0x0' == it.split()[-1]) {
Properties systemProperties = System.getProperties();
String proxyServer = ['reg', 'query', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'].execute().text
proxyServer.eachLine {
if (it.trim().startsWith('ProxyServer')) {
String proxyServerHostPort = it.split()[-1]
systemProperties.setProperty('http.proxyHost', "${proxyServerHostPort.split(':')[0]}");
systemProperties.setProperty('http.proxyPort', "${proxyServerHostPort.split(':')[1]}");
systemProperties.setProperty('https.proxyHost', "${proxyServerHostPort.split(':')[0]}");
systemProperties.setProperty('https.proxyPort', "${proxyServerHostPort.split(':')[1]}");
}
if (it.trim().startsWith('ProxyOverride')) {
String nonProxyHosts = it.split()[-1].replace(';', '|');
systemProperties.setProperty('http.nonProxyHosts', "${nonProxyHosts}");
systemProperties.setProperty('https.nonProxyHosts', "${nonProxyHosts}");
}
}
}
}
}
}
Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' | findstr /R "^Proxy"
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
// https://docs.gradle.org/current/userguide/build_environment.html#sec:accessing_the_web_via_a_proxy
if (DefaultNativePlatform.getCurrentOperatingSystem().isWindows()) {
String proxyEnabled = ['reg', 'query', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', '/v', 'ProxyEnable'].execute().text
proxyEnabled.eachLine {
if (it.trim().startsWith('ProxyEnable')) {
if ('0x0' == it.split()[-1]) {
String proxyServer = ['reg', 'query', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'].execute().text
proxyServer.eachLine {
if (it.trim().startsWith('ProxyServer')) {
String proxyServerHostPort = it.split()[-1]
println "systemProp.http.proxyHost=${proxyServerHostPort.split(':')[0]}"
println "systemProp.http.proxyPort=${proxyServerHostPort.split(':')[1]}"
println "systemProp.https.proxyHost=${proxyServerHostPort.split(':')[0]}"
println "systemProp.https.proxyPort=${proxyServerHostPort.split(':')[1]}"
}
if (it.trim().startsWith('ProxyOverride')) {
String nonProxyHosts = it.split()[-1].replace(';', '|');
println "systemProp.http.nonProxyHosts=${nonProxyHosts}"
println "systemProp.https.nonProxyHosts=${nonProxyHosts}"
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment