Gradle任务开始时不调用

时间:2019-06-12 18:57:53

标签: android gradle groovy javadoc kotlin-dokka

我正在尝试使用Dokka来为Javadoc和Kotlindoc构建Javadoc

task dokkaDoc(type: org.jetbrains.dokka.gradle.DokkaAndroidTask) {

    println("Inside the task dokkaDoc")

    moduleName = 'data'
    outputFormat = 'javadoc'
    outputDirectory = "$buildDir/docs/javadoc"

}



task taskA(type: Zip, dependsOn: dokkaDoc) {
    println("Starting task A")
    classifier 'dokkaDoc'
    extension "zip"
    from "$buildDir/docs/kotlindoc"
    archiveName 'a.zip'
}

task taskB(type: Zip, dependsOn: dokkaDoc) {

    println("Starting task B")
    classifier 'dokkaDoc'
    extension "zip"
    from "$buildDir/docs/kotlindoc"
    archiveName 'b.zip'

}

当我尝试执行taskA时,也会执行taskB。

Output:
>gradlew :Project:a

> Configure project :Project
Inside the task dokkaDoc
Starting task A
Starting task B

1 个答案:

答案 0 :(得分:0)

通过将println添加到任务定义中,它们将在配置时而不是在运行时打印

您可以通过将doFirstdoLast块添加到任务来将其更改为仅在任务执行时打印:

task dokkaDoc(type: org.jetbrains.dokka.gradle.DokkaAndroidTask) {
    doFirst {
        println "Running the task dokkaDoc"
    }
    moduleName = 'data'
    outputFormat = 'javadoc'
    outputDirectory = "$buildDir/docs/javadoc"
}

task taskA(type: Zip, dependsOn: dokkaDoc) {
    doFirst {
        println "Starting task A"
    }
    classifier 'dokkaDoc'
    extension "zip"
    from "$buildDir/docs/kotlindoc"
    archiveName 'a.zip'
}

task taskB(type: Zip, dependsOn: dokkaDoc) {
    doFirst {
        println "Starting task B"
    }
    classifier 'dokkaDoc'
    extension "zip"
    from "$buildDir/docs/kotlindoc"
    archiveName 'b.zip'
}