Search code examples
gradlevfsapache-commons-vfs

configure proxy for gradle-vfs plugin


tl;dr:

How do I configure the https proxy to be used by the gradle-vfs plugin? It does seem to ignore the normal java/gradle proxy configuration.

Full Details

Based on this gradle file I try to use gradle to create reveal.js slides from asciidocs.

I have configured the proxy settings using a gradle.properties file with content similar to this:

systemProp.http.proxyHost=myproxy
systemProp.http.proxyPort=8080
systemProp.http.nonProxyHosts=localhost
systemProp.https.proxyHost=myproxy
systemProp.https.proxyPort=8080
systemProp.https.nonProxyHosts=localhost

While this configuration works for gradle, when performing java builds (it downloads plugin and dependencies), vfs which is used in the reference build file fails:

:download FAILED

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\workspaces\myproject\build.gradle' line: 47

* What went wrong:
Execution failed for task ':download'.
> Could not connect to HTTP server on "github.com".

Line 47 is the first beginning with cp in this block:

task download << {
    mkdir downloadDir
    vfs {
         cp "zip:https://github.com/asciidoctor/asciidoctor-reveal.js/archive/${asciidoctorBackendVersion}.zip!asciidoctor-reveal.js-${asciidoctorBackendVersion}",
            templateDir, recursive:true, overwrite:true
        cp "zip:https://github.com/hakimel/reveal.js/archive/${revealjsVersion}.zip!reveal.js-${revealjsVersion}",
            revealjsDir, recursive:true, overwrite:true
    }
}

Solution

  • One (my) solution is to add vfs options defining the Proxy parameters. This could be more sophisticated e.g. by building a task to derive the parameters from the system environment, but this one works:

    task download << {
        mkdir downloadDir
        vfs {
            options 'vfs.http.proxyHost' : 'mylocalsquid.lokal'
            options 'vfs.http.proxyPort' : '3128'
            options 'vfs.https.proxyHost' : 'mylocalsquid.lokal'
            options 'vfs.https.proxyPort' : '3128'
            cp "zip:https://github.com/asciidoctor/asciidoctor-reveal.js/archive/${asciidoctorBackendVersion}.zip!asciidoctor-reveal.js-${asciidoctorBackendVersion}",
                templateDir, recursive:true, overwrite:true
            cp "zip:https://github.com/hakimel/reveal.js/archive/${revealjsVersion}.zip!reveal.js-${revealjsVersion}",
                revealjsDir, recursive:true, overwrite:true
        }
    }
    

    This was derived from the documentation at http://ysb33r.github.io/groovy-vfs/1.0/docs/product-documentation.html