Avoid duplication in settings.gradle files

I have at least 8 settings.gradle files in the root project directories of a large project all with a piece of code like this, that is becoming annoying:

pluginManagement
{
    repositories
	{
        gradlePluginPortal()
    }
    includeBuild '../tipos'
}

dependencyResolutionManagement
{
    versionCatalogs
	{
        libs
		{
			from(files("../gradle/libs.versions.toml"))
		}
    }
}

Is there a way to unify this code somewhere to avoid this duplication, so that I can change it in only one place?

The plugin repository you define is the default, so you can just leave it out. The version catalog definition could be made in a settings plugin, for example from one in tipos.

1 Like

Is it possible to develop a settings plugin with just the Groovy DSL? If so, what declaration(s) should I use or plugin that I have to apply to say that it’s a settings plugin, not a project plugin?

Yes, name it foo.settings.gradle.

1 Like

I have just tried it and it worked. Thank you very much.

1 Like