How to detect which gradle project that contains classes that have dependency on an updated class?

For example if I have class A1 in project A, B1 in project B, C1 in project C, and D1 in project D. Both class A1 and C1 have dependency on class D1. When I updated class D1 I want to track which projects contains A1 and C1. The objective is that I want to only build project A, C, and D on my CI pipelines.

PS: I use monorepo

This is somewhat outside of the scope of circleci or any general CI system as you are looking for a solution that fully understands the working of a gradle-based environment. Solutions like circleci are more focussed on the more general git storage environment.

If you are working with gradle you should look at dependencies between subproject management such as

https://docs.gradle.org/current/userguide/declaring_dependencies_between_subprojects.html

The outcome is likely to be that you start to build your project more around gradle and less around circleci. So rather than circleci knowing about 3 different projects (A,C and D) it ends up knowing about just ‘the project’ and gradle decides what should be built on any change.