Exclude or replace default test runtime dependency with instrumented jar

I have a project with main and test roots.
By default, tests are compiled and run with main dependency.

But, my code is instrumented after compilation and I would like to replace test runtime dependency on compiled classes to the jar with instrumented classes.

Compile dependency should stay the same, so IDE could properly import the project.

If I just add testRuntimeOnly dependency on jar, gradle adds it, but in the classpath it is going after pure compiled classes and classloader uses pure classes anyway.