【问题标题】:How to build artifacts conditionally based on project version using gradle?如何使用 gradle 根据项目版本有条件地构建工件?
【发布时间】:2016-11-04 12:26:36
【问题描述】:

您好,我有一个名为 A 的项目,由三个模块(核心、移动网络)组成,结构如下:

A
   --settings.gradle
   --build.gradle
   --core
     --build.gradle
   --web
      --build.gradle
   --mobile
      --build.gradle

我的 settings.gradle 是这样的:

include 'core'
include 'web'
include 'mobile'

已经有不同的版本,直到 2.0 版我们才提供移动模块,在此之前我们不想构建“移动”模块。现在我有 1.0、1.1、1.2、2.0、2.1 版本,我们在每次代码提交之前测试和检查编译。我们是这样做的:

VERSIONS=( "1.0" "1.1" "1.2" "2.0" "2.1 )
for version in "${VERSIONS[@]}"; do (gradle -PspringBootVersion=${version} clean install uploadArchives); done

这样在 2.0 之前的版本中,它仍然会构建“移动”模块,这当然会失败。我的问题是如何有条件地检查和构建项目?提前致谢。

【问题讨论】:

    标签: gradle spring-boot


    【解决方案1】:
    include 'core'
    include 'web'
    
    if("${springBootVersion}" ==~ /2\.[0-9]) {
        include include 'mobile'
    }
    

    真的很简单,我只修改了上面的settings.gradle,然后就得到了正确的结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-09
      • 1970-01-01
      • 2014-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      相关资源
      最近更新 更多