Multi-project build: Create fileset with project and its dependencies

We have got a web application with a common backend and an old UI and a new UI. Currently, it is possible to deploy either into a Tomcat, and the WEB-INF/lib directory contains the jar files required for the UI and the backend.

I would like to deploy two web apps into one Tomcat, one web app for each UI. These two web apps should share the backend classes. To avoid classloader issues, my understanding is that the backend jars should be in the Tomcat shared/lib directory, instead of inside each web app’s WEB-INF/lib.

(I’ll attach a backend “manager” instance to the servlet context for the new UI, and I’ll change the old UI to obtain that instance.)

We’ve got a multi-project build, one set of projects for the backend, another set for the old UI and yet a third set for the new UI.

What I’ve got so far is this: the cargo plugin defines a setting sharedClasspath (a FileCollection), and I’ve added my backend projects there and the corresponding jar files are copied to shared/lib. What is missing is that I also need to copy the dependencies of these jar files.

As an example, let this be a backend project:

project(':backend') {
    dependencies {
        implementation 'org.apache.commons:commons-lang3:3.1'
    }
}

So now I will need to copy backend.jar and commons-lang.jar (not the exact file names) to the Tomcat shared/lib directory. I’m able to include backend.jar as follows:

...
    sharedClasspath = layout.files(project(':backend').jar.archivePath)
...

But how do I get all dependencies of :backend and the artifact fully qualified file names for them?

project(':backend').configurations.api.allArtifacts seems to be empty. I also tried the configuration implementation. And project(':backend').configurations.api.dependencies seems to contain Dependecy objects which don’t tell me the artifact file name.

I’ve now found out how to do it:

...
    sharedClasspath = layout.files(
        project(':backend').jar.archivePath,
        project(':backend').configurations.runtimeClasspath.resolvedConfiguration.files,
    )
...

It took me a while to figure out that runtimeClasspath was the right configuration, and I only found through another forum post that I can do .resolvedConfiguration.files to access the actual files.