Replacement of overwrite rule

I’m an Android developer. In one of our projects, we use “UMLGraph” to generate javadoc with UML graphs. It was working fine so far (we were on gradle-5.4.1) but it doesn’t work anymore now that we have moved to gradle-6.1.1.

Here are the lines that we use in our ‘build.gradle’ file:

task javadoc(overwrite: true, dependsOn: build) {
    setDescription('Generates Javadoc API documentation with UMLGraph diagrams')
    ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
    doLast {
        def javaFilePath = file('src/main/java')
        if (javaFilePath.exists()) {
            ant.javadoc(classpath: "ext.androidJar",
                    sourcepath: file('src/main/java'),
                    Doctitle: "XXXXX",
                    Windowtitle: "XXXXX ",
                    bottom: "COPYRIGHT XXXX.",
                    header: "<b> ${appName}-${appVersionName}<b> ",
                    packagenames: '*',
                    destdir: "../docs/javadoc/",
                    private: 'true',
                    docletpath: file('UmlGraph.jar'),
                    charset: 'UTF-8',
                    encoding: 'UTF-8',
                    docencoding: 'UTF-8') {
                doclet(name: 'org.umlgraph.doclet.UmlGraphDoc')
                            param(name: '-inferrel')
                            param(name: '-inferdep')
                            param(name: '-qualify')
                            param(name: '-postfixpackage')
                            param(name: '-hide', value: 'java.*')
                            param(name: '-collpackages', value: 'java.util.*')
                            param(name: '-nodefontsize', value: '9')
                            param(name: '-nodefontpackagesize', value: '7')

        } else {
            print("!!! Cannot find source path !!!");

Now that we are using Gradle 6 we get the following error:
Unnecessarily replacing a task that does not exist is not supported. Use create() or register() directly instead. You attempted to replace a task named ‘javadoc’, but there is no existing task with that name.

Could you please point me how to update this rule and find an alternative to the “overwrite” rule?

Thanks for your help

You don’t need an alternative here. Just don’t specify overwrite: true when you have nothing to overwrite in the first line:

1 Like