有人知道是否可以在Maven存储库中找到源jar吗?


当前回答

要下载某些特定的源代码或javadoc,我们需要包括GroupIds -它是一个逗号分隔的值,如下所示

mvn dependency:sources -DincludeGroupIds=com.jcraft,org.testng -Dclassifier=sources

注意,分类器不是用逗号分隔的,要下载javadoc,我们需要使用分类器javadoc再次运行上述命令

mvn dependency:sources -DincludeGroupIds=com.jcraft,org.testng -Dclassifier=javadoc

其他回答

Maven存储库确实提供了下载jar源代码的简单方法。

我将使用“spring-boot-actuator-autoconfigure”的演示来解释它。

Go to maven repository - https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-actuator-autoconfigure The page lists various versions. Click-on to desired one, let's say, 2.1.6.RELEASE - https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-actuator-autoconfigure/2.1.6.RELEASE The page have link "View All" next to "Files". Click it - https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-actuator-autoconfigure/2.1.6.RELEASE/ The page lists various files including the one for sources - https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-actuator-autoconfigure/2.1.6.RELEASE/spring-boot-actuator-autoconfigure-2.1.6.RELEASE-sources.jar

否则,你总是可以“git克隆”从github的回购,如果它在那里,并获得特定的代码。

正如其他人解释的那样,您可以使用“mvn dependency:sources”命令获取并生成您正在使用的依赖项的sources jar。

注意:有些依赖项没有sources.jar,因为这些依赖项不包含源代码,只包含一个pom文件。例如spring-boot-starter-actuator。 在这个例子中:

初学者pom是一组方便的依赖描述符,可以包含在应用程序中。您可以获得所需的所有Spring和相关技术的一站式商店,而不必寻找示例代码和复制粘贴依赖描述符负载。

参考:Spring引导启动器介绍

如果您想手动找到任何工件的源jar文件,请转到特定工件的maven存储库位置,并在Files中单击“view All”。你可以找到源jar文件。

如果您正在使用Eclipse,我建议同时下载源代码和第三方库的Javadocs。

右键点击项目和下载两个截图如下。

下载Javadocs意味着通常可以从第三方库中获得方法的上下文帮助,其中包含有用的参数描述等。如果你不太了解图书馆,这是很重要的。在某些情况下,我发现当源代码不可用时,Javadocs是可用的。

IntelliJ idea的maven idea插件允许您指定是否应该解析和下载源代码和java文档

mvn idea:idea -DdownloadSources=true -DdownloadJavadocs=true

在IntelliJ IDEA中,您可以在导入时通过打开“自动下载源”选项自动下载工件源:

设置→构建、执行、部署→构建工具→Maven→导入