Groovy, Java and Kotlin interdependencies during compilation

Hi,
I have an existing project which has Groovy and Java Files and are inter operable.
Now, we are planning to replace groovy files with Kotlin (being statically typed and other useful features)
We were able to get Kotlin and Groovy to work with each other using some of the documentation present here
https://docs.gradle.org/6.1/release-notes.html?_ga=2.3636659.2076751051.1632355651-1220928735.1628625673#defining-compilation-order-between-groovy,-scala-and-java

This is what I have so far in the build.gradle

    **tasks.named('compileGroovy') {**
**        // Groovy only needs the declared dependencies (and not the result of Java compilation)**
**        classpath = sourceSets.main.compileClasspath**
**    }**

**    tasks.named('compileKotlin') {**
**        // Kotlin also depends on the result of Groovy compilation**
**        classpath += files(sourceSets.main.groovy.classesDirectory)**
**    }**

The source sets in the build.gradle look like

 sourceSets {
        main {
            java.outputDir = file("$buildDir/classes/main")
            groovy.outputDir = file("$buildDir/classes/main")
            kotlin.outputDir = file("$buildDir/classes/main")
            sourceSets.main.output.resourcesDir file("$buildDir/classes/main")

            sourceSets.main.kotlin.srcDirs = ["src/main/java", "src/main/groovy", "src/main/kotlin"]
            sourceSets.main.groovy.srcDirs = ["src/main/java", "src/main/groovy"]
            sourceSets.main.java.srcDirs   = []
        }


        testIntegration {
            java.outputDir = file("$buildDir/classes/testIntegration")
            groovy.outputDir = file("$buildDir/classes/testIntegration")
            java.srcDirs = ["src/test-integration/java", "src/test/java"]
            groovy.srcDirs = ["src/test-integration/groovy", "src/test/groovy"]
            resources.srcDir file('src/test-integration/resources')
            sourceSets.testIntegration.output.resourcesDir file("$buildDir/classes/testIntegration")
            compileClasspath = sourceSets.main.output + sourceSets.test.output + configurations.testIntegrationCompile
            runtimeClasspath = output + compileClasspath + configurations.testIntegrationRuntime
        }
    }

Now,till we have all the groovy classes converted into Kotlin, there is a scenario where we have Java classes also needing Kotlin classes during compilation and Java class is not able to locate the Kotlin classes, most likely because compileKotlin dependsOn compileGroovy dependsOn compileJava . By the time compileJava is processed, we don 't have the Kotlin classes ready.
With the help of the documentation we were able overcome the issue with kotlin and groovy by providing groovy classes in compileKotlin’s classpath but how does one do the same for compileJava (if it is the way to go )

The below did not help and also using “classpath += files(sourceSets.main.kotlin.classesDirectory)” resulted in an error message.

   tasks.named('compileJava') {

        classpath = sourceSets.main.kotlin

    }

Just the way groovy has stubs and are provided to Kotlin for compilation , is there something similar for Kotlin and Java issue .(I tried kapt plugin but did not go too far with that) The other option is to convert the Java file into Kotlin but we might have many Java files which need Kotlin.
Any pointers will be helpful ? Thank you