gradle - 如何使用 gradle 根据项目版本有条件地构建工件?

标签 gradle spring-boot

嗨,我有一个名为 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 之前的版本中,它仍然会构建“移动”模块,这当然会失败。我的问题是如何有条件地检查和构建项目?提前致谢。

最佳答案

include 'core'
include 'web'

if("${springBootVersion}" ==~ /2\.[0-9]) {
    include include 'mobile'
}

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

关于gradle - 如何使用 gradle 根据项目版本有条件地构建工件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40422648/

相关文章:

jboss5.x - Gradle提供了 war 中存在的依赖关系

Android SDK 位置 vs 构建服务器,如何设置?

java - 如何在非接口(interface)非抽象类中使用JDBI @Transaction注解?

amazon-web-services - AWS XRAY SDK 问题 : Failed to begin subsegment named 'Amazon S3' : segment cannot be found

java - 作为 InputStreamResource 返回时 Excel 文件未打开

java - 如何调用新的 @Async 方法但等待一个条件?

android - 如何在android库中导出依赖项

android - 错误 :Server returned HTTP response code: 403 for URL: https://services. gradle.org/distributions/gradle-4.4-rc-3-all.zip

spring-boot - Spring Boot:无法使用Gradle构建

java - Feign 无法解析名称