Help in adding jar file to the sourceSets in build.gradle

I had a case where i need to run gradle tests using the jar file listed in the specific directory.

In build.gradle, i have the below code which will create a build directory with classes and the tests run using those classes.

sourceSets {
test {
java.srcDir ‘src/main/java’
resources.srcDir ‘src/main/resources’
java.exclude ‘**’
Our build code is deployed onto a different machine so i want to run the tests using the jar file.

Tried adding the classpath to jar file in the test task but the tests are looking into the build directory from the sourceSets. Is there a way i can remove the sourceSets and use the jar file to run the tests?
test {
classpath = files(’$STAGE/build/test/libs/*.jar’)