0

I am trying to build javadoc using Dokka for javadoc and kotlindoc

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'

}

When I try to execute taskA, taskB also gets executed.

Output:
>gradlew :Project:a

> Configure project :Project
Inside the task dokkaDoc
Starting task A
Starting task B
dcanh121
  • 4,665
  • 11
  • 37
  • 84

1 Answers1

1

By adding println to the task definition, they are being printed at configuration time, not at runtime

You can change that to only print when the task is executed by adding a doFirst or doLast block to the task:

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'
}
tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • Why only the print statement in doFirst? – dcanh121 Jun 13 '19 at 14:31
  • The build script gets effectively executed when it is parsed. This configures the tasks. If you move everything into a doFirst, your tasks won't be configured when it comes to execute them – tim_yates Jun 13 '19 at 14:36
  • When I run the taskA, DokkaAndroidTask is executed, builds the output directory as /docs/javadoc. But after that when I run taskB it does not build the output directory. – dcanh121 Jun 13 '19 at 15:01
  • Not sure what you mean – tim_yates Jun 13 '19 at 16:44