Javadoc task does not refer package-info how is expected. How set package flag?

Using the Gradle / Groovy ant support isn’t that complicated. You just have to structure your call to match the Ant task API rather than the Gradle one. For the settings you’ve shown, you’d end up putting something like the below as your task action:

ant.javadoc(access: access, charset: charset, classpath: classpath.asPath, destdir: destDir) {
    srcDirs.each { srcDir -> packageset(dir: "${srcDir}") }
    links.each { href -> link(href: href) }
}

You would need to declare the variables I’ve used here with proper annotations in a custom task class or hard code them and use the runtime API for ad-hoc task inputs/outputs for proper UP-TO-DATE checking.

The other alternative is extending the current implementation to provide extra arguments. You need the source paths and the root package name. This implementation adds some arguments based on a rootPackage that you would now need to specify and replaces source with sourceDirectorySet because we need to capture the source directory sets before they are only available as individual source files.

class CustomJavadoc extends Javadoc {

    String rootPackage
    SourceDirectorySet sourceDirectorySet
    
    @Override
    @TaskAction
    protected void generate() {
        getOptions().addStringOption('subpackages', rootPackage)
        getOptions().addPathOption('sourcepath', ';').setValue(getSourceDirectorySet().getSrcDirs().asList())
        super.generate()
    }

    @Input
    String getRootPackage() {
        return rootPackage
    }

    void setSourceDirectorySet(SourceDirectorySet sourceDirectorySet) {
        this.sourceDirectorySet = sourceDirectorySet
        setSource(sourceDirectorySet)
    }

}

Usage example:

task customJavadoc (type: CustomJavadoc) {
    classpath = sourceSets.main.compileClasspath
    rootPackage = 'com.manuel.jordan'
    sourceDirectorySet = sourceSets.main.allJava
    options.charSet('UTF-8')
    options.memberLevel = JavadocMemberLevel.PRIVATE
}