【问题标题】:Including subprojects using a wildcard in a Gradle settings file在 Gradle 设置文件中包含使用通配符的子项目
【发布时间】:2011-01-18 19:34:31
【问题描述】:

在 Gradle 中,您需要在“settings.gradle”文件中定义要构建的子项目。要构建三个子项目,您需要执行以下操作:

include "child1", "child2", "child3"

我遇到的问题是我有很多项目要包括在内。有没有办法在这个定义中使用通配符?我正在寻找这样的东西:

include "*"

这当然行不通。这会更容易使用,因为我有很多子项目要包括在内。有没有办法自动将子目录包含为项目?

【问题讨论】:

    标签: java groovy build gradle


    【解决方案1】:

    include rootDir.listFiles().findAll { 
         it.isDirectory() 
         && !( it =~ ".*/\\..*") // don't add directories starting with '.'
         && !( it =~ "^\\..*") // don't add directories starting with '.'
        }.collect { 
            it.getName() 
        }.toArray(new java.lang.String[0])
    

    帮我搞定了

    【讨论】:

      【解决方案2】:

      以下代码支持任意深度的项目层次结构:

      rootDir.eachFileRecurse { f ->
          if ( f.name == "build.gradle" ) {
              String relativePath = f.parentFile.absolutePath - rootDir.absolutePath
              String projectName = relativePath.replaceAll("[\\\\\\/]", ":")
              include projectName
          }
      }
      

      【讨论】:

        【解决方案3】:

        你能做这样的事情吗:

        include (1..10).collect { "Child$it" }
        

        要包括“Child1”到“Child10”吗?

        显然,您需要将收集更改为某种文件夹扫描,但如果快速测试有效,那么扫描就有很好的机会

        【讨论】:

        • "child1" 和 "child2" 仅用于示例。项目的真实名称中没有数字。我希望有一个内置功能,而无需在目录中列出文件,但我想可能没有。
        • 是否包含 new File( '.' ).listFiles().findAll { it.isDirectory() } .collect { it.name } 工作?
        猜你喜欢
        • 2022-12-25
        • 1970-01-01
        • 2018-08-28
        • 1970-01-01
        • 1970-01-01
        • 2014-03-31
        • 1970-01-01
        • 1970-01-01
        • 2010-10-03
        相关资源
        最近更新 更多