如何让我的自定义gradle任务运行?

时间:2019-07-17 19:33:13

标签: gradle

我有一个gradle项目,要从中生成两个工件-一个Java jar和一个附加文件的压缩包。

所以我将以下内容添加到了build.gradle

def serviceName = "kafka-schemas"

task packageDistribution(type: Copy) {
    from "$buildDir/resources/main"
    include "*.avsc"
    into "$buildDir/schemas"
}

task archive(type: Tar) {
    dependsOn 'packageDistribution'
    compression = 'GZIP'
    from("$buildDir/schemas") {
        include "**/*.avsc"
    }
    into("${serviceName}")
}

project.tasks.findByName('build') dependsOn archive
project.tasks.findByName('build') dependsOn packageDistribution

但是,当我运行gradle clean build时,它不会运行我的任务。

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

尝试一下:

processResources.dependsOn('packageDistribution')
task packageDistribution(type: Zip) {
archiveFileName = "xxxxx.zip"
    destinationDirectory = file("$buildDir/dist")

    from "xxxx"
}