Compile tests with dependences in jar file

Recently, I was asked to do a rather unusual task, to make a jar file with tests and include dependencies there, and I have been struggling with this task for a week but to no avail, I learned how to compile tests into a jar, but alas, it does not contain dependencies

task Testjar(type: Jar) {
    duplicatesStrategy = 'exclude'
    from sourceSets.main.output + sourceSets.toSet().output

Instructions for me don’t work: How To Run Junit Tests From The Command Line (don’t compile dependencies)

My project structure:

Any idea what is compile and run tests from jar project