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


当前回答

配置和运行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>

其他回答

如果一个项目创建了一个项目源代码的jar,并将其部署到maven存储库中,那么你会发现它:)

仅供参考,源构件通常是由maven-source-plugin创建的。这个插件可以将项目的主要或测试源绑定到jar存档中,如配置源插件中所述:

(…)生成的jar文件将由finalName的值加上“-sources”(如果它是主要源代码)来命名。否则,它将是finalName加上“-test-sources”(如果它是测试源)。

附加的文本用来描述一个工件(这里是“-sources”或“-test-sources”)称为分类器。

要声明对使用分类器的工件的依赖,只需添加<classifier>元素。例如:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate</artifactId>
  <version>3.2.7.ga</version>
  <classifier>sources</classifier>
</dependency>

注意,您通常不会这样做,大多数ide都支持从主工件下载源(和/或JavaDoc),而无需显式地声明对它们的依赖。

最后,还要注意一些存储库搜索引擎允许使用分类器搜索工件(至少Nexus支持高级搜索)。请看这个搜索的例子。

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

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

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

您可以在这个相关问题中找到相关信息:获取附加到Eclipse的源jar文件,以获得maven管理的依赖关系 如果你使用eclipse maven插件,那么使用'mvn eclipse:eclipse -DdownloadSources=true'

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

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

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

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