Run code at both build time and runtime

I have a subproject “persistence” that is used by a plugin “persistence-plugin” and by other subprojects that are part of the main program. With maven that wasn’t a problem, because each module is built separately and installed in the local maven repo. When using gradle subprojects, it’s not possible to have one subproject’s build script depend on another subproject.

How do I share code between build time and runtime?

It seems like included builds are the answer. But I feel this will get very complex quickly, because “persistence” depends on other subprojects that are also dependencies of the main program (e.g. a “utils” subproject that’s a dependency of most other subprojects). Is there an easier way, this seems like a common requirement?