Gradlew behind a proxy

后端 未结 16 1418
一个人的身影
一个人的身影 2020-12-04 12:26

I have a sample from Gaelyk (called Bloogie) and it is using gradlew.

I am behind a proxy.

I\'ve read gradle docs and found this:

gradle.properties

相关标签:
16条回答
  • 2020-12-04 12:31

    An excerpted answer from the linked thread below. It shows how to do this more programtically. Hope it helps

    task setHttpProxyFromEnv {
        def map = ['HTTP_PROXY': 'http', 'HTTPS_PROXY': 'https']
        for (e in System.getenv()) {
            def key = e.key.toUpperCase()
            if (key in map) {
                def base = map[key]
                //Get proxyHost,port, username, and password from http system properties 
                // in the format http://username:password@proxyhost:proxyport
                def (val1,val2) = e.value.tokenize( '@' )
                def (val3,val4) = val1.tokenize( '//' )
                def(userName, password) = val4.tokenize(':')
                def url = e.value.toURL()
                //println " - systemProp.${base}.proxy=${url.host}:${url.port}"
                System.setProperty("${base}.proxyHost", url.host.toString())
                System.setProperty("${base}.proxyPort", url.port.toString())
                System.setProperty("${base}.proxyUser", userName.toString())
                System.setProperty("${base}.proxyPassword", password.toString())
            }
        }
    }
    

    See this thread for more

    0 讨论(0)
  • 2020-12-04 12:36

    After lots of struggling with this and banging my head against a wall, because nothing on my system was using a proxy: it turned out that my ** Android Emulator instance ** itself was secretly/silently setting a proxy for me via Android Emulator > Settings > Proxy and had applied these settings when playing around with it weeks earlier in order to troubleshoot an issue with Expo.

    If anyone is having this issue, make sure you check 100% to see if indeed no custom proxy settings are being used via: ./gradlew installDebug --info --debug --stacktrace and searching for proxyHost in the log output to make sure of this. It may be your emulator.

    0 讨论(0)
  • 2020-12-04 12:37

    To add more nuances, for my case, when I have multiple gradle.properties files in both USER_HOME/.gradle and the project root, I encountered the authenticationrequired 407 error, with the bellow log:

    CONNECT refused by proxy: HTTP/1.1 407 authenticationrequired

    This caused my systemProp.https.proxyPassword and systemProp.http.proxyPasswordblank in the gradle.properties file under USER_HOME/.gradle, while the gradle.properties file under the project root remained password info.

    Not sure the exact reason, But when I remove one gradle.properties in the project root and keep the file in the USER_HOME/.gradle, my case is resolved.

    0 讨论(0)
  • 2020-12-04 12:38
    systemProp.http.proxyUser=userId
    systemProp.http.proxyPassword=password
    

    same with https......

    0 讨论(0)
  • 2020-12-04 12:40

    All you have to do is to create a file called gradle.properties (with the properties you mentioned above) and place it under your gradle user home directory (which defaults to USER_HOME/.gradle) OR in your project directory.

    Gradle (the wrapper too!!!) automatically picks up gradle.properties files if found in the user home directory or project directories.

    For more info, read the Gradle user guide, especially at section 12.3: Accessing the web via a proxy

    0 讨论(0)
  • 2020-12-04 12:40

    Add the below in your gradle.properties file and in your gradle/wrapper/gradle-wrapper.properties file if you are downloading the wrapper over a proxy

    If you want to set these properties globally then add it in USER_HOME/.gradle/gradle.properties file

    ## Proxy setup
    systemProp.proxySet=true
    systemProp.http.keepAlive=true
    systemProp.http.proxyHost=host
    systemProp.http.proxyPort=port
    systemProp.http.proxyUser=username
    systemProp.http.proxyPassword=password
    systemProp.http.nonProxyHosts=local.net|some.host.com
    
    systemProp.https.keepAlive=true
    systemProp.https.proxyHost=host
    systemProp.https.proxyPort=port
    systemProp.https.proxyUser=username
    systemProp.https.proxyPassword=password
    systemProp.https.nonProxyHosts=local.net|some.host.com
    ## end of proxy setup
    
    0 讨论(0)
提交回复
热议问题