英文:
Why an arbitrary repository, such as nexus/artifactory, defines in maven block in Gradle?
问题
repositories {
mavenCentral()
maven {
//任意仓库
}
}
为什么在 Gradle 的 maven {}
块中定义任意仓库,比如 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'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.
</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)):
> 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.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论