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


当前回答

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引导启动器介绍

其他回答

配置和运行maven-eclipse插件(例如从命令行mvn eclipse:eclipse)

   <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
        </plugins>
    </build>

下载任何工件使用

mvn dependency:get -Dartifact=groupId:artifactId:version:packaging:classifier

对于Groovy源代码,这将是

mvn dependency:get -Dartifact=org.codehaus.groovy:groovy-all:2.4.6:jar:sources

对于Groovy的javadoc,您将使用

mvn dependency:get -Dartifact=org.codehaus.groovy:groovy-all:2.4.6:jar:javadoc

这将把给定的工件放到本地Maven存储库中,通常是$HOME/.m2/存储库。

Dependency:sources只下载项目依赖项的源代码,不下载插件源代码,也不下载插件内部定义的依赖项的源代码。

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

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

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

你可以,如果他们被上传。通常它们被称为“frameworkname-version-source(s)”

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

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