为什么在gradle任务中添加类型会影响下面示例中的println语句?

时间:2016-03-10 17:53:29

标签: java gradle

构建

task taskX() << {
    println 'taskX'
}
task taskY(type:Copy) << {
    println "taskY"
}

输出:

C:\dev\how-to-confluence\NYSSIS-WS\ear>gradlew -q taskX
taskX
C:\dev\how-to-confluence\NYSSIS-WS\ear>gradlew -q taskY
C:\dev\how-to-confluence\NYSSIS-WS\ear>gradlew -version

------------------------------------------------------------
Gradle 2.10
------------------------------------------------------------

Build time:   2015-12-21 21:15:04 UTC
Build number: none
Revision:     276bdcded730f53aa8c11b479986aafa58e124a6

Groovy:       2.4.4
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.7.0_67 (Oracle Corporation 24.65-b04)
OS:           Windows 7 6.1 amd64

注意: taskY中的println调用不输出。

1 个答案:

答案 0 :(得分:0)

为了提供文件实际上是复制的反馈,我需要利用复制任务中可用的eachFile closure

task taskX() << {
    println 'taskX'
}

task taskY(type:Copy) {
    eachFile{
        println "taskY"
    }
    from 'src/main' into 'build'
}