为什么这个gradle任务缺少源代码?

时间:2016-06-08 19:29:28

标签: gradle

Gradlew newb在这里,试图找出为什么当我调用我的任务时它会错过它的预期来源。我的印象是任务基于gradle explodeJars --info

以正确的顺序执行
$ gradle explodeJars --info
...
:copyJarsOver (Thread[main,5,main]) completed. Took 0.051 secs.
:explodeJars (Thread[main,5,main]) started.
:explodeJars
Skipping task ':explodeJars' as it has no source files.
:explodeJars UP-TO-DATE
:explodeJars (Thread[main,5,main]) completed. Took 0.0 secs.

有问题的任务:

task copyJarsOver(type: Copy, dependsOn: ["buildAll"]) {
  from 'some/folder/cool.jar'
  from 'another/folder/fancy.jar'
  from 'best/folder/awesome.jar'
  into 'build/modules'
  rename { String fileName ->
    fileName.replace('.jar', '.zip')
  }
}

// Explodejars doesn't work when first ran, works second time <?>
task explodeJars(type: Copy, dependsOn: ["copyJarsOver"]) {
  fileTree(dir: 'build/modules').each({ zipModule ->
    def module = zipTree(zipModule)
    from module
  })
  into 'build/explodedJars'
}
explodeJars.mustRunAfter copyJarsOver

1 个答案:

答案 0 :(得分:1)

好的,所以我对任务的生命周期感到困惑......

任务内的代码在配置时执行 - 此时文件尚未复制到文件夹中。如果我希望它在执行时运行,我应该把它放在doLast中。

无论哪种方式,从接受像from { fileTree(...).collect { zipModule -> zipTree(zipModule) } }

这样的闭包