IDE如何自动下载依赖源
How does IDEs automatically downloads the sources for dependencies
现在大多数 IDE 都支持下载源代码以添加依赖项,当我们想在源代码中查看 Class/Interface/Method 定义时,它非常有效。
我的问题是关于 IDE 如何在线找出源代码(包含源代码的工件)并自动 下载它们。
假设我想将我的库发布为开源库并使其成为 Maven 中央仓库的一部分,我需要做什么才能支持此 下载源代码 功能?
在 Maven 生态系统中,源文件通常使用 maven-source-plugin:
捆绑到特定的包中
The Source Plugin creates a jar archive of the source files of the current project. The jar file is, by default, created in the project's target directory.
按照惯例,源码包的名称以-sources.jar
结尾,如hsqldb-1.8.0.7-sources.jar
。名称的 sources
部分在 Maven 中称为 classifier:
The classifier distinguishes artifacts that were built from the same POM but differ in content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.
[...] use case for classifiers is to attach secondary artifacts to the project's main artifact. If you browse the Maven central repository, you will notice that the classifiers sources and javadoc are used to deploy the project source code and API docs along with the packaged class files.
知道这个约定,IDE 很容易从 Maven central or from other configured Maven repositories.
中检索依赖项的源文件
现在大多数 IDE 都支持下载源代码以添加依赖项,当我们想在源代码中查看 Class/Interface/Method 定义时,它非常有效。
我的问题是关于 IDE 如何在线找出源代码(包含源代码的工件)并自动 下载它们。
假设我想将我的库发布为开源库并使其成为 Maven 中央仓库的一部分,我需要做什么才能支持此 下载源代码 功能?
在 Maven 生态系统中,源文件通常使用 maven-source-plugin:
捆绑到特定的包中The Source Plugin creates a jar archive of the source files of the current project. The jar file is, by default, created in the project's target directory.
按照惯例,源码包的名称以-sources.jar
结尾,如hsqldb-1.8.0.7-sources.jar
。名称的 sources
部分在 Maven 中称为 classifier:
The classifier distinguishes artifacts that were built from the same POM but differ in content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.
[...] use case for classifiers is to attach secondary artifacts to the project's main artifact. If you browse the Maven central repository, you will notice that the classifiers sources and javadoc are used to deploy the project source code and API docs along with the packaged class files.
知道这个约定,IDE 很容易从 Maven central or from other configured Maven repositories.
中检索依赖项的源文件