How to centralize the publication repos configs

Right now we can configure plugin and dependency resolution repos in the project settings configs and developers love it.

Is there an idiomatic way to also centrally configure publication repos (short of burying them in a convention plugin)? I haven’t used Gradle in a while so I figured I should check here first :slightly_smiling_face:

I guess it can be done by hooking every project’s plugin manager and customizing the publishing extension when maven-publish is detected:

Or possibly by configuring a bogus resolution repo and then doing:

publishing.repositories.add(project.repositories.getByName(“abc”))

Or is there a reason why that would be a bad idea altogether?

What is wrong with doing it in a convention plugin?
That would exactly be the idiomatic way.

by hooking every project’s plugin manager and customizing the publishing extension when maven-publish

which you would do in a convention plugin, wouldn’t you?
Either a convention plugin that for example also applies maven-publish and does the configuration,
or a convention plugin that uses pluginManager.withPlugin("maven-publish") { ... } to react to the plugin being applied by some other means.

I would not declare a resolution repository just to then reuse it as publication repository, if that is even possible, I’m not sure about that.

Thanks for the feedback.

The resolution repos in settings are very visible, and we also configure declaration of repos in projects to be an error.

This makes it very easy to find the publication repo details (which for certain reasons is a big deal in this firm).

For the record, the settings file plugin approach is:

gradle.rootProject.allprojects { pluginManager.withPlugin… }

Putting the publication repos in convention plugin is less discoverable and requires more discipline to keep consistent.

1 Like