How to understand the subproject dependence

When I build some project like apache kafka, I find that some subproject are relied on the other subproject, I’d like to know what is the necessity for that. Conflict in compiling? Or other reason
which is the form in build.gradle:

project(':core') {
    dependencies {
        api project(':clients')
        implementation project(':metadata')

Actually, the project(':core') { ... } is doing cross-project configuration just like allprojects { ... } or subprojects { ... } would do and is highly discouraged bad practice.

But other than that, I don’t really get the question.
The project core is using classes from the project clients in its public API and classes from the project metadata in its implementation, so it declares the dependencies.
This is nothing different to depending on a third-party library by coordinates in that regard.

When I compile Java file, I can compile them at the same time without the class file, because Java can load the referenced Java source file directly. So I wonder if Gradle can also do the compile tasks parallel to save time.

“at the same time”, exactly.
If you tell the compiler “compile these three source files”.
If you could do this cross-compile tasks, it would mean you would compile the same sources multiple times which doesn’t make too much sense and would waste time, not save time.

If you want as much parallelity as possible, then you need to use the configuration cache.
With the configuration cache all tasks that do not have a dependency on each other or an ordering constraint can run in parallel, even tasks from within the same project.

1 Like

OK, thanks. I will try that.

oh, and so is there any limitation that we cannot use the configuration cache.

If your build is not compatible with it, you cannot use it.