What's the best way to share a compileOnly dependency between subprojects?

I have a multiproject build where subprojects depend on a shared utility project via a project reference. Pre-Gradle, the overall project was monolithic, and that hasn’t changed much, so I’m aware that there are larger design issues that will eventually need to be dealt with. For now, however, the utility project consolidates shared functions and publishes a number of 3rd party jar dependencies for other projects to use.

I wanted to add the lombok annotation processor for all projects to use, so I put its compileOnly dependency in the common utility project, but unlike other jar dependencies consolidated there, the compileOnly one was not inherited by other projects. If this were a built/maven dependency, then compileOnly assets wouldn’t make it into the published artifact, but in this case it’s all local, so the lack of propagation was unexpected.

Is there a better way to get lombok to other projects than to have to add compileOnly to each one directly or setup an allprojects/afterEvaluate block? It’s an annotation processor, so compileOnly is the correct way to include it. I’d like to be able to do that for all projects from one place.

Local or not, compileOnly dependencies should not leak, that’s their whole point.

That’s the way to go.