Share source files among different gradle projects

I’m writing an app comprised of a java backend and an android frontend communicating through grpc.
I’d love for the project to be structured like this:

  • root_dir (not a gradle project, just a directory)
  • backend (gradle project for the java backend)
  • frontend (gradle project for the android frontend)
  • grpcapi (this directory contains just the common .proto files used by both backend and frontend, it’s not a gradle project)

How can I tell to the ‘backend’ and ‘frontend’ gradle projects to include the .proto files in the ‘grpcapi’ directory?

Please note that the protobuf-gradle-plugin must be loaded and configured differently in both the ‘backend’ and ‘frontend’ projects.

I ended up doing this in both backend’s and frontend’s build.gradle files:

sourceSets {
    main {
        proto {
            srcDir '../grpcapi'

Not sure if this is the best solution though.

I’d do the following

  1. Turn grcapi into a gradle project
  2. Create a ‘default’ Configuration in the grcapi project
  3. Add the proto files to the ‘default’ configuration (either the directory or a zip/jar)
  4. In the other projects use
dependencies {
   runtime project(':grcapi') 

See here for a similar solution