Make extension function available in both settings.gradle of buildSrc and root

Hey, my company publishes some custom plugins and dependencies to an internally hosted artifactory instance. I’m trying to declare this repository in my :buildSrc’s settings.gradle and my top level settings.gradle, but I want to avoid duplicating this declaration. I’ve added a third gradle module that just declares an extension function:

    fun RepositoryHandler.customRepo(provider: ProviderFactory) {
        maven("https://release-url") {
            mavenContent { releasesOnly() }
            artifactoryCredentials(provider)
        }
        maven("https://snapshot-url") {
            mavenContent { snapshotsOnly() }
            artifactoryCredentials(provider)
        }
    }

    fun AuthenticationSupported.artifactoryCredentials(provider: ProviderFactory) {
        val userName = provider.propOrEnv("artifactory_username").get()
        val apiKey = provider.propOrEnv("artifactory_api_key").get()
        credentials {
            username = userName
            password = apiKey
        }
    }

    fun ProviderFactory.propOrEnv(key: String): Provider<String> {
        return gradleProperty(key).orElse(environmentVariable(key))
    }

What’s the best way to make this function available in both (buildSrc & root) settings.gradle’s dependencyManagement block?

Hey my company publishes some custom plugins and dependencie gradle-community #community-support :slight_smile: