I am currently trying to centralize my repositories declaration for all my projects by using dependencyResolutionManagement within an init.d init script.
But when I want to declare new centralized repositories in a multi-project settings.gradle.kts using dependencyResolutionManagementagain, it removes all my repositories declared by my init script.. Is it normal? How should I do it according to Gradle best practices?
I’d say not using an init script at all is the best idea.
By declaring your repositories in an init script, your projects fail to build as soon as you move them to a different machine, or share them with someone else, or use a different user account, or just remove that init script for some reason.
Having said that, you probably need to show an MCVE.
I just tried and it works just fine and as expected, both repositories are used.
You should not use an init script to centralize your repository definitions; you should use only the root-level settings.gradle(.kts) file: Centralizing Repository Declarations
Thanks for both of your answers, using an init script is really useful in my case since I am working on multiple projects that uses the same base repositories.. Is there an alternative to init scripts that is not copying the same repositories to every project I work on?
Use a convention plugin that you apply where you want its effect.
You can publish it somewhere and apply it from there, or you can also include the build that builds that plugin into your other projects.
We thought about that, but the problem is that if we release a convention plugin that declare repositories, it would be released on the repositories that needs to are declared by the convention plugin..
Well, yeah, one death you have to die.
Either you do it cleanly and need to have the repo once per project,
or you do it bad-practice and your build will nowhere work without manually putting the init script there which will then probably also affect all other builds it should not affect.
Your convention plugin can at least reduce the amount of declaring the repo to 1 instead of declaring it manually as plugin repo, dependency repo, publication repo, …