Gradle transitive dependencies with repository

In my gradle project i have two subprojects, one called api and the other core:

api.gradle

plugins {
    id 'java-library'
}

repositories {
    maven { url 'https://repo.spongepowered.org/repository/maven-public/' }
}

dependencies {
    api('org.spongepowered:spongeapi:8.0.0')
}

core.gradle

dependencies {
    implementation(project(':api'))
}

The problem is that when I try to compile the core subproject I get the following error:

> Could not find org.spongepowered:spongeapi:8.0.0-SNAPSHOT.

Adding the spongepowered repository in core.gradle works, but I wanted to know if there is a way to also add the repository transitive to reduce boilerplate.

As you’ve seen, each project resolves with its own configured repositories. You can centralize the definition of repositories for all subprojects using dependencyResolutionManagement in your settings.gradle(.kts) file.

https://docs.gradle.org/current/userguide/declaring_repositories.html#sub:centralized-repository-declaration

Thanks for the answer, this is a feasible solution, but the problem is that I have other subprojects that do not have to use these repositories at all, adding it on dependencyResolutionManagement will expose it to them and it is not necessary at all, Is there another way for a subproject to use the repositories of a dependency?

If a project declares repositories then, by default, repositories declared by the project will override whatever is declared in settings. Perhaps you could have a baseline of repos in settings and then override in the special projects?

If that’s not enough control, then extracting the repository configuration logic into a plugin(s) or precompiled script plugin(s) should give you enough control to centrally manage the repos in whatever manner required. These plugins do not need to be separate projects and can be embedded using buildSrc or a composite build.

To make it clear.
Chris is not only suggesting better alternatives.
He didn’t explicitly spell it, but no, there is no way to have repositories work transitively.
A project has to define the repositories where it gets its dependencies and their transitive dependencies.
Otherwise you would open a big door to bad actors and also would make it harder to enforce policies like “only use an in-house mirror with sanctioned dependencies” and similar.