【问题标题】:How to overriding the maven's url when running gradle运行gradle时如何覆盖maven的url
【发布时间】:2015-08-03 10:05:24
【问题描述】:

我在 build.gradle 中有一个 maven 设置,如下所示。你可以看到我正在使用一个 nexus 服务器进行内部包管理。

repositories {
    jcenter()
    maven {
        url 'http://192.168.0.2:8081/nexus/content/groups/public/'
    }
}

首先,我不能在云环境中构建这个项目,因为这个 nexus 服务器不在云中。
其次,可以使用域名从云端访问此 nexus 服务器。
第三,我无法将此 url 更改为域名,因为构建作业是由 Jenkins 运行的。

所以我想知道 gradle 是否支持在命令行中覆盖这个 url 值,比如使用 -P?或者我可以运行另一个 gradle 任务来完成替换工作?

【问题讨论】:

    标签: maven jenkins gradle


    【解决方案1】:

    如果您知道 nexus 的 ip 并且可以访问您的构建服务器,我建议您修改 etc/hosts 文件,而不是添加以下行:

    192.168.0.2 name.of.nexus.host

    如果你不能用这种方式解决它,你可以用 -P 传递一个命令行值。

    gradle someTask -PcommandLineProjectProp=commandLineProjectPropValue 
    

    它为您提供了在构建中使用的 commandLineProjectPropValue。

    要在你的 url 字符串中使用它,你必须使用双 qoutes("") 和 $commandLineProjectPropValue。

    所以:

    url "$(commandLineProjectPropValue)rest/of/path" 
    

    【讨论】:

      猜你喜欢
      • 2020-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-15
      • 1970-01-01
      • 2013-05-28
      • 2013-05-04
      相关资源
      最近更新 更多