为什么一个任意的仓库,比如nexus/artifactory,在Gradle的maven块中定义?

huangapple go评论65阅读模式
英文:

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

问题

repositories {
    mavenCentral()
    maven {
        //任意仓库
    }
}

为什么在 Gradlemaven {} 块中定义任意仓库,比如 Nexus、Artifactory 等。显然这是另一个仓库。
或者我们这样做是因为构建工具的作者提供了这样的 DSL 吗?
可以假设 "maven-repository" 只是 Nexus、Artifactory 等遵循的特定二进制仓库结构。


<details>
<summary>英文:</summary>


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


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

</details>


# 答案1
**得分**: 1

以下是翻译好的部分:

"Gradle要为您获取依赖项,它必须知道如何将依赖项符号(例如`com.google.guava:guava:31.0.1-jre`)转换为实际的URL,以便找到所需的构件(以及有关该构件的其他信息)。

原则上,每个仓库供应商(Maven、Nexus、Artifactory等)都可以发明自己的方案来执行此操作,Gradle将难以支持所有这些方案。

幸运的是,仓库供应商已经收敛(至少在Java领域)到主要两种格式:

* Maven:https://maven.apache.org/repository/layout.html
* Ivy:https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:ivy_repositories

这两种仓库格式是Gradle支持的内容(支持的仓库类型):

> Gradle支持各种依赖项来源,无论是格式还是连接方式。您可以从以下来源解析依赖项:
>
> * 不同的格式
>
>   * Maven兼容的构件仓库(例如:Maven Central)
>   * Ivy兼容的构件仓库(包括自定义布局)
>   * 本地(平面)目录

当您以以下形式指定仓库时:

repositories {
maven {
//任何仓库
}
}


实际上是在告诉Gradle,“任何仓库”使用Maven兼容的格式。"

<details>
<summary>英文:</summary>

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:

* Maven: https://maven.apache.org/repository/layout.html
* Ivy: https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:ivy_repositories

And these two repository formats are what Gradle supports ([Supported repository types](https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:repository-types)):

&gt; Gradle supports a wide range of sources for dependencies, both in terms of format and in terms of connectivity. You may resolve dependencies from:
&gt;
&gt; * Different formats
&gt;
&gt;   * a Maven compatible artifact repository (e.g: Maven Central)
&gt;   * an Ivy compatible artifact repository (including custom layouts)
&gt;   * local (flat) directories

When you specify a repository in the form

    repositories {
        maven {
            //any repos
        }
    }

You are actually telling Gradle that the &quot;any repos&quot; repository uses the Maven compatible format.

</details>



huangapple
  • 本文由 发表于 2023年6月12日 18:22:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455700.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定