Best Practice for MultiProject Build Import

Hi,
I am moving over a large java project from an ant build system to gradle. It is being done for multiple reasons, and seems to be a necessary step forward.
The project has say
4 projects each dependent on the previous ones, B is dependent on A, e.g.
A->B->C->D
Each project is in a separate git repository.
A,B,C each produce a runnable jar and a library jar.
D solely produces an application.
I can not change the code structure.

How would I write in my build.gradle to produce 2 jars, one with main and one without, so I can have for example

  1. a runnable jar for Project A with main
  2. a library jar without main from Project A that Project B can consume and find

My goal is to not simply rewrite the build.xml file from the ant setup, but correctly translate it to gradle, so it is clean and efficient.

Thanks for any advice!

I have been reading a bit, and have come up with possibly two ways to go about it,
1] Write a custom gradle plugin, that for projects A,B,C creates a consumable library jar without a main specified, and an application that can be run with main.

2] Slightly change the structure for each project A,B,C, by creating a subproject which is the application, and consumes the library from the root project.

Would either of these solutions be preferred? One of the goals is to have simpler build files which are easier to maintain.