【问题标题】:Why gradle automatically includes parent folder as a subproject when adding a subfolder as subproject为什么将子文件夹添加为子项目时,gradle会自动将父文件夹包含为子项目
【发布时间】:2017-09-25 15:18:10
【问题描述】:

我有以下简单的设置:

文件结构

$ tree
.
├── build.gradle
├── modules
│   ├── rest-model
│   └── rest-resource
└── settings.gradle

文件内容

settings.gradle

def MODULES = 'modules'

file(MODULES).eachDir {
    include ":${MODULES}:${it.name}"
}

build.gradle

task hello {
    doLast {
        subprojects.each {
            println it.name
        }
    }
}

上面的任务hello会打印出所有子项目。我只期待两个子项目:rest-modelrest-resource。但是,我得到了三个:modulesrest-modulerest-resource。这是gradle输出:

$ gradle hello
Starting a Gradle Daemon (subsequent builds will be faster)

> Task :hello
modules
rest-model
rest-resource


BUILD SUCCESSFUL in 2s
1 actionable task: 1 executed

那么,为什么 gradle 会自动将父文件夹 modules 包含为子项目呢?我可以防止吗?

【问题讨论】:

    标签: gradle


    【解决方案1】:

    使用includeFlat 代替include

    def MODULES = 'modules'
    
    file(MODULES).eachDir {
        includeFlat ":${MODULES}:${it.name}"
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-03
      • 1970-01-01
      • 2011-08-20
      • 2013-01-12
      • 2014-01-13
      • 1970-01-01
      • 1970-01-01
      • 2016-12-02
      相关资源
      最近更新 更多