Questions about "api" in java-library plugin

I understand that if a dependency dep is declared as api , it means that dep is used as ABI and is inherited by downstream projects’ compileClassPath. The problem is, if the downstream projects use the ABI, shouldn’t it declare dep as their dependency? If the downstream projects expect to inherit dep other than declare it, isn’t this the occasion where undeclared transitive dependencies are used directly?

Yes and no.

If you for example have class A in dep.
class A extends class Z in trans.
Now if consumer (of dep) class B makes new A(), compilation would fail as trans is missing without the consumer using trans directly.

If the consumer also uses trans directly, I agree that it should also declare that usage with a declared dependency.

You might be interested in the dependency-analysis-android-gradle-plugin (ignore the “android”, that’s just an unlucky naming choice) which helps in getting these things declared properly.

Thanks for your reply, that’s exactly what i’m confused about.