【问题标题】:configure proxy for gradle-vfs plugin为 gradle-vfs 插件配置代理
【发布时间】:2016-09-09 12:38:48
【问题描述】:

tl;博士:

如何配置 gradle-vfs 插件使用的 https 代理?它似乎确实忽略了正常的 java/gradle 代理配置。

详细信息

基于gradle file,我尝试使用 gradle 从 asciidocs 创建reveal.js 幻灯片。

我使用 gradle.properties 文件配置了代理设置,其内容类似于:

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

虽然此配置适用于 gradle,但在执行 java 构建(它下载插件和依赖项)时,参考构建文件中使用的 vfs 失败:

: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".

第 47 行是此块中第一个以 cp 开头的:

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
    }
}

【问题讨论】:

    标签: gradle vfs apache-commons-vfs


    【解决方案1】:

    一个(我的)解决方案是添加定义代理参数的 vfs 选项。 这可能更复杂,例如通过构建一个任务来从系统环境中获取参数,但是这个工作:

    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
        }
    }
    

    这来自http://ysb33r.github.io/groovy-vfs/1.0/docs/product-documentation.html的文档

    【讨论】:

    • 使用 gradle.properties 中定义的属性可以用 project.property("systemProp.http.proxyPort") 替换字符串字面量,其中字符串是属性的名称。
    猜你喜欢
    • 2011-08-24
    • 1970-01-01
    • 2018-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    相关资源
    最近更新 更多