Modeling circular dependencies of an existing Java project in Gradle

I have an existing pretty big Intellij Idea Java project that I am creating a Gradle build for.
This project has around 40 modules. A module in Intellij is a set of source files and its dependencies. The dependencies can be external jar files, or other modules.

The modules in this project create a cycle of dependencies. This cycle is not direct but after 5-6 or more iterations the cycle is formed. Intellij compiles this without any issue, as long as Java source level is the same on all modules.

Is there a way in Gradle to accommodate to this project? Whether the Intellij module is mapped to Gradle project or source set or any other construct doesn’t matter, as long as Gradle compiles this project properly.
The project is huge and possibility to do any restructuring just to fit it to the Gradle is not likely.