1

How can I list all the repositories available to the project's buildscript?

I'm migrating some projects from very simple Gradle builds to start using some custom platforms and convention plugins but I'm having some trouble importing some of those artifacts into the buildscript.

I've read this question and tried the following:

tasks.register("listrepos") {
    doLast {
        println("Repositories:")
        project.buildscript.repositories.map { it as MavenArtifactRepository }
            .forEach { println("Name: ${it.name}; url: ${it.url}") }
    }
}

But the list is always empty.

It's awkward because I was expecting at least the gradlePluginPortal() repository to be listed here.

EDIT:

After @PrasadU's answer I added the following snipped to my build.gradle.kts file. I just updated it to the Kotlin DSL syntax:

project.afterEvaluate {
    println("Running project afterEvaluate")
    project.buildscript.repositories.asMap.forEach { (name, repo) ->
        println("$name >> ${repo.name}")
    }
}

The problem is that project.buildscript.repositories.asMap is empty.

Daniel Schröder
  • 547
  • 4
  • 18

1 Answers1

0

you do not need a task for that ...

project.afterEvaluate {
    project.buildscript.repositories.getAsMap().forEach {
        name, repo -> println("$name >> ${repo.properties.displayName}")
    }
}
PrasadU
  • 2,154
  • 1
  • 9
  • 10
  • 1
    I edited my question based on your answer. But the set of repositories is empty. That's probably why I'm having trouble resolving my artifacts. But the repositories are declared and I'm surely resolving some artifacts. That list shouldn't be empty, right? – Daniel Schröder Aug 23 '22 at 16:27