Upgrading to Gradle 6.7.1 ClassLoader doesn't see classes from /main

In the JUnit /test I have a test that enumerates classes from /main, looking for specific ones. It worked on Gradle 5.x, but on 6.7.1 ClassLoader.getResources(“my/package”) no longer includes the classes from /main. If I put some of the classes from /main to /test they are getting found. Aside from this, when I run the test in Android Studio ClassLoader.getResources(“my/package”) lists the classes from /main without problems. As Studio uses Gradle, I suspect there might be some new setting, to make the classes from /main visible to ClassLoader run in unit test, from /test folder?

The code is as follows:

    fun checkHashCollisions() {
        val classLoader = Thread.currentThread().contextClassLoader!!
        val path = packageName.replace('.', '/')
        val resources: Enumeration<URL> = classLoader.getResources(path)

Stackoverflow post with this issue: Android: after Gradle update to 6.7.1 ClassLoader in JUnit test no longer lists all resources - Stack Overflow

Please advice, how can I make the classes from /main to be returned from ClassLoader.getResources() in a /test.

In Gradle 6.7.1 I had to include the directory with the code to the test sourceSets. Afterwards the classloader from junit started to see the classes and return them in Enumeration.

sourceSets {
        test {
            java.srcDirs += ['src/main']

Would be thankfull for any insights, why this was not needed in previous versions of Gradle? Was the main directory included into sourceSet by default?