I have a question about Dependency Resolution Mana...
# plugin-development
y
I have a question about Dependency Resolution Management. I’ve developed a settings plugin that injects resolution repositories during the settings phase. I’m using PREFER_SETTINGS to prioritize repositories from the input, but this causes the build to ignore the resolution repositories configured in my
build.gradle
file. Here’s a simple example illustrating what the plugin accomplishes:
Copy code
public class MyPluginSettings implements Plugin<Settings> {
    @Override
    public void apply(Settings settings) {
        settings.getDependencyResolutionManagement().getRepositoriesMode().set(RepositoriesMode.PREFER_SETTINGS);
        settings.getDependencyResolutionManagement().getRepositories().maven(mavenArtifactRepository -> {
            mavenArtifactRepository.setUrl(repoUrl);
        });
    }
}
Is there a way to use the repositories from the settings phase while still falling back to the ones specified in
build.gradle
? In other words, I’d like to use PREFER_SETTINGS with a fallback to PREFER_PROJECT. How can I achieve that? Thanks in advance.
v
You cannot. This would open a whole lot of repository hell in what should be merged with what in which order and so on. So for simplicity and clarity it was designed in a way that either the repositories from the settings are used, or the repositories from the project.
I usually tend to set "FAIL_ON_PROJECT" and have the repositories centrally declared in the settings script. A project consuming your plugin can still add repositories, but only in their settings script.
If your plugin is not something private, but a public plugin, I highly recommend not to add repositories anyway, or at least not without an opt-in.
The actual build should always have the control over where things are resolved from. For example some company guidelines dictate that exclusively in-house repositories are used for everything that are more reliable and safe.