Generate Javadoc for ten distinct modules in a same root project

Hi all, I need your help, I have a root project containing other ten modules, I want generate the javadoc for each module, now I have this lines and works ok, but Are there a better way to do this?, because currently I put this lines in each build.gradle file.

The lines are the next:

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
destinationDir = file("…/javadoc/module1" )
failOnError false
}

See the link below for the various options for sharing build logic

https://docs.gradle.org/current/userguide/organizing_build_logic.html