Best way to do file dependencies between modules

I used Sample structuring software projects as inspiration to structure my project but I have run into a problem on now best to decare file dependencies between module
I have a folder strukture like this (super psudo code but I hope you get the idea)

root (settings.gradle)
|___ openapis (settings.gradle)
|      |___my_manager (build.gradle) /src/main/resources/openapi.yaml
|___service (settings.gradle)
      |___my_manager_service(build.gradle)

The build.gradle for my_manager_service needs to know the location in the follow task

openApiGenerate {
skipValidateSpec = true
generatorName = “spring”
configFile = “${projectDir}/src/main/resources/config.json”.toString()
inputSpec = file(‘…/…/openapis/game-manager/src/main/resources/openapi.yaml’).absolutePath
}

I have only been able to make it work when I set it as an absolute file path - But what is the best way of doing it?

One way to do it is to create a new dependency configuration that uses variant attributes to select the resources (such a variant is produced by the java plugin).
Since inputSpec is a Property<String>, we can use a provider to transform our new dependency config into a single file.

plugins {
    id 'java'
    id "org.openapi.generator" version "6.0.0"
}

configurations {
    openapi {
        canBeConsumed = false
        canBeResolved = true
        attributes {
            attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, LibraryElements.RESOURCES))
        }
    }
}

dependencies {
    openapi 'your.group:game-manager' // the module containing the openapi.yaml
}

openApiGenerate {
    skipValidateSpec = true
    generatorName = "spring"
    inputSpec = providers.provider {
        // find the first matching file, returning null if not found
        configurations.openapi.asFileTree.files.find {
            it.name == 'openapi.yaml'
        }?.absolutePath
    }
}

This could be more nicely abstracted out of the buildscript and into a plugin that is part of your project.

1 Like