0

我正在尝试使用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
4

1 回答 1

1

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

doFirst您可以通过向任务添加或doLast块将其更改为仅在执行任务时打印:

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'
}
于 2019-06-12T19:03:08.620 回答