Using task output directory as Java srcDir

With Gradle 6.5, querying a mapped output value of a task before it has completed has been deprecated.

I’ve been using this to declare a subfolder of the @OutputDirectory of a task as java.main.srcDir:

    val task = project.tasks.create("sablecc", SableccTask::class) {
      sableccClasspath = sableccConfiguration
    }
    val sourceSet = java.sourceSets.getByName("main")
    sourceSet.java.srcDir(task.outputDir.map { it.dir("java") })
    sourceSet.resources.srcDir(task.outputDir.map { it.dir("resources") })

What would be the best practice for this use-case without triggering the deprecation?

Does the lack of responses mean that the solution is too obvious, or that there is no good solution, and the deprecation has perhaps come somewhat prematurely without a proper replacement?