How to share outputs between projects

Until now I used the following to create my war:

tasks.named('war').configure {
	classpath = project.sourceSets.production.runtimeClasspath + project(':shared').sourceSets.production.runtimeClasspath

However, accessing the runtimeClasspath of the other project has been deprecated and gives a warning on Gradle 7.6. So I want to fix that. I spent a lot of time on this and can’t figure out a (good) way to do that.

Actually using just classpath = project.sourceSets.production.runtimeClasspath almost works - because the current project depends on shared anyway and hence the jars from shared come in. The only problem (as far as I can see) is that things declared in productionRuntimeOnly in the shared project don’t get added to the war.

So what’s the “correct” way to migrate that code? Thanks!

This is the documentation about how to properly share things between projects: Sharing outputs between projects

Or maybe you actually want to create a “production” feature variant as documented at Modeling feature variants and optional dependencies