Search code examples
javagradlegroovydsl

Why an arbitrary repository, such as nexus/artifactory, defines in maven block in Gradle?


repositories {
    mavenCentral()
    maven {
        //any repos
    }
}

Why an arbitrary repository, such as Nexus, Artifactory, e.t.c defines in maven {} block in Gradle.
It's obviously another repositories.
Or we do similarly just because such DSL provided by build tool's authors?
Can assume, that "maven-repository" is just a specific binary repo structure followed by Nexus, Artifactory, e.t.c.


Solution

  • For Gradle to fetch dependencies for you it must know how to translate a dependency notation like com.google.guava:guava:31.0.1-jre into the actual URLs where it can find the required artefact (and additional information about that artefact).

    In principle every repository vendor (Maven, Nexus, Artifactory, ...) could have invented their own scheme for doing this and Gradle would have a hard time to support all of them.

    Fortunately the repository vendors have converged (at least in the Java landscape) on mostly two formats:

    And these two repository formats are what Gradle supports (Supported repository types):

    Gradle supports a wide range of sources for dependencies, both in terms of format and in terms of connectivity. You may resolve dependencies from:

    • Different formats

      • a Maven compatible artifact repository (e.g: Maven Central)
      • an Ivy compatible artifact repository (including custom layouts)
      • local (flat) directories

    When you specify a repository in the form

    repositories {
        maven {
            //any repos
        }
    }
    

    You are actually telling Gradle that the "any repos" repository uses the Maven compatible format.