Android unit test unable to resolve class under test after updating gradle

I updated my Gradle plugin version from 3.3.2 to 3.5.2 and my Gradle distribution from 5.3.1 to 5.6.4. I also invalidated caches and restarted. After this change, my unit tests are failing to compile and complaining that a class, let’s call it Foo, is unable to be resolved.

The unit test is located in module A whereas Foo is located in module B. Module A has both an “implementation” and “testImplementation” dependency on module B. Foo is located under a package within the “test” directory. So for example: test/java/com/mycompany/mypackage/

If I open the unit test within Android Studio, everything looks fine. No red underlines on the Foo import, and I can control click to Foo just fine. It’s only when I attempt to compile/run it that it complains that Foo can’t be resolved.

If I relocate Foo from “test” to “main”, the unit test compiles and runs just fine. Any idea how to fix this? I’d like to keep Foo under test since it’s only used for testing.