“test” folder is not able to import classes from “main” folder's “resources”

I’m new to gradle so please forgive my ignorance.

enter image description here

I’ve a gradle task created such that it creates class files in ‘main’ folder’s resources folder.

I want my “test” folder to be able to import those class files but currently I’m not able to.

This is my build.gradle:

dependencies {

//testCompile fileTree(dir: "${buildDir}/libs", include: ["*.jar"])
testCompile fileTree(dir: "src/main/resources", include: ["*.class"])
testCompile sourceSets.main.output

}

task executeCodegen(type: JavaExec) {
main = “codegen.x.Codegen”
classpath = sourceSets.testCodegen.runtimeClasspath
args “-outputDir”, “src/main/resources”
}

tasks.executeCodegen.dependsOn tasks.assemble
tasks.build.dependsOn tasks.executeCodegen
tasks.test.dependsOn tasks.executeCodegen
tasks.compileTestJava.dependsOn tasks.executeCodegen

In my test when I do an import of my class files in resources folder, I’m getting a cannot resolve symbol. Also this is failing:

Task :compileTestJava is failing due to:
package x does not exist

Can someone please help?