Shared settings between independent repositories

I am a little bit stumped at the moment. When I set out to reduce repetition in a few Gradle projects I figured what I want is simple, but it seems that I was wrong. I have 3 projects that live in separate git repositories and are built separately. These projects do however share a few common settings. These include:

  • repository definitions for plugins (“pluginManagement”)
  • repository definitions for dependencies (“dependencyResolutionManagement”)
  • version catalog

All in all, their settings.gradle files are all identical apart from the rootProject.name. This includes stuff like corporate repositories, the version of the version catalog artifact and more.

I find myself copying the settings.gradle file between all the projects whenever a change is made. I figured there must be a mechanism to load the same settings for all of them through a plugin or similar, but there does not seem to be a way. My question is therefore: How can independent projects that are not built together share a common settings.gradle or ideally inherit from a common settings.gradle?

In an ideal world i would store the settings file in some remote repository and be able to simply reference the URL in another settings file. Alternatively a plug-in seems reasonable, though it seems a plug-in can’t really be applied to the settings file. It would also require a repository definition for the plug-in, which would be repeated.

Are there any best practice approaches for this issue?

1 Like

You can have a settings plugin, but it will be an instance of Plugin<Settings> instead of Plugin<Project>. There’s a little bit of a chicken-or-egg problem there since:

  1. You’re trying to share/centralise repository settings
  2. Plugins need a repository

Perhaps you’d prefer the following in settings.gradle

apply from: 'http://path/to/1.3.3/shared-settings.gradle'

Remember to include the version in the URL so it’s versioned/repeatable

Hi, thanks for the response. I see, yeah I figured the repository problem was gonna be a thing, though it would be reduced to a single one. I had tried a Plugin<Settings>, but I couldn’t figure out how to apply it correctly in settings (it wasn’t working).

Does the apply from thing work in settings too? I thought I had tried it to no avail. Maybe I specified the URL wrong in Kotlin. Anyway, my repositories were not going to the build file causing errors.

Does the apply from thing work in settings too?

Yes, Settings implements PluginAware