Gradle zip任务既不失败也不工作

时间:2017-12-29 20:29:12

标签: gradle

我正在尝试创建一个自定义的Gradle 4.3.1任务:

  1. 运行生成./gradlew build工件的build/libs/myapp.jar;然后
  2. 创建一个myapp-1.0.zip ZIP文件,其内容包括:
    • build/libs/myapp.jar;和
    • ./AppGuide.md;和
    • ./app-config.json
  3. 这是我最好的尝试:

    task zipMeUp(type: Zip) {
      String zipName = 'myapp-1.0.zip'
    
      doFirst {
        tasks.build
      }
    
      from 'build/libs/myapp.jar'
      from 'AppGuide.md'
      from 'app-config.json'
      into zipName
    }
    

    当我运行它(./gradlew zipMeUp)时,我得到以下输出:

    HarveyZ:myapp myuser$ ./gradlew zipMeUp
    
    BUILD SUCCESSFUL in 2s
    1 actionable task: 1 executed
    

    但实际上似乎没有发生任何事情(目录中没有myapp-1.0.zip文件)。 知道修复/解决方案是什么吗?

1 个答案:

答案 0 :(得分:1)

请勿使用doFirst,请使用dependsOn

task zipMeUp(type:Zip, dependsOn :[build]) {
    String zipName = 'myapp-1.0.zip'

    from 'build/libs/myapp.jar'
    from 'AppGuide.md'
    from 'app-config.json'

    version = "1.0"
    baseName = "myapp"
}