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


当前回答

下载任何工件使用

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只下载项目依赖项的源代码,不下载插件源代码,也不下载插件内部定义的依赖项的源代码。

其他回答

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

在Eclipse中

右键单击pom.xml 选择Run As -> Maven generate-sources 默认情况下,它将在.m2文件夹中生成源代码

Pre-Requisite:

Maven应该使用Eclipse进行配置。

如果你知道groupId和aritifactId,你可以像这样生成下载url。

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.2.3</version>
    </dependency>

http://central.maven.org/maven2/ch/qos/logback/logback-classic/

你会得到一个像这样的页面,选择你需要的版本,只是享受它!

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

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

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