DNS resolution error in doLast exec vs type:Exec

Alright, I think I need another life lesson here…

Here is a simple Exec to download a file:

task getConfigFile (type: Exec) {
    executable("curl")
    args('-u', "${username}:${password}")
    args("-sS", "--fail")
    args("--retry", "2", "--retry-connrefused", "--retry-max-time", "50")
    args("--connect-timeout", "5")
    args('-o', "${configFiledir}/${project.name}.json")
    args("https://artifactory.de.company.com/artifactory/control/config/ab/${project.name}.json")
}

It works. All good.
Then another task which I believe should do the same thing:

task getConfigFile {
    doLast {
        exec {
            executable("curl")
            args('-u', "${username}:${password}")
            args("-sS", "--fail")
            args("--retry", "2", "--retry-connrefused", "--retry-max-time", "50")
            args("--connect-timeout", "5")
            args('-o', "${configFiledir}/${project.name}.json")
            args("https://artifactory.de.company.com/artifactory/control/config/ab/${project.name}.json")
        }
    }    
}

This one fails because curl is not able to resolve the URL https://artifactory.de.company.com/
Why is that?


A bit of background…

I live in a development jail surround by VPN, proxies and the hell. I have to use Windows with WSL and a quite convoluted environment to make things talk. In it, the /etc/resolve.conf seems correct, which is the reason why I believe the first Task above works.

Anyway, this question isn’t about making the 2nd Task work. I’m honestly curious to understand why both Tasks behave differently.
I could imagine a situation in which variables (proxy etc) aren’t propagated to the exec (though I wouldn’t be able to justify it either)… but DNS? :frowning:

I found out the reason. That’s no Gradle mystery. It’s just a silly mistake.
One of the tools we integrate doesn’t accept the existence of Proxy variables (HTTPS_PROXY, HTTPS_PROXY and NO_PROXY) even though it doesn’t use them at all (ugh!!!)

Then, deep in one of our Gradle build scripts, there was this:

tasks.withType(Exec).all {
    environment.remove('http_proxy')
    environment.remove('https_proxy')
    environment.remove('no_proxy')
    environment.remove('HTTP_PROXY')
    environment.remove('HTTPS_PROXY')
    environment.remove('NO_PROXY')
}

Sorry for the trouble!

1 Like