Maven——总是下载源代码和javadocs

是否有一种方法可以将maven配置为总是下载源和javadocs?每次指定-DdownloadSources=true -DdownloadJavadocs=true(这通常伴随着运行mvn compile两次,因为我忘记了第一次)变得相当乏味。

202034 次浏览

我认为每个插件都可以做到。参见Maven书中的这一章

你可以配置依赖插件来下载源代码(尽管我自己没有尝试过:-)。

打开settings.xml文件~/.m2/settings.xml(如果它不存在就创建它)。添加添加了属性的部分。然后确保activeProfiles包含新的概要文件。

<settings>


<!-- ... other settings here ... -->


<profiles>
<profile>
<id>downloadSources</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
</profiles>


<activeProfiles>
<activeProfile>downloadSources</activeProfile>
</activeProfiles>
</settings>

编辑:正如Jingguo Yao提到的,这只适用于Eclipse IDE -同样也可以在您选择的IDE中配置。在eclipse中通过Window ->偏好→Maven菜单,尽管这可能必须在每个工作空间级别和新的Eclipse安装中完成。

或者在你的pom.xml中配置maven-dependency-plugin在一个单独的概要文件中,并根据需要运行它——将它保留在主构建中会导致在不需要源代码或java文档的构建节点上的构建时间(不必要的拉长(更不用说空间了)。最好在一些组织或部门的父pom.xml中配置,否则它将在不同的地方重复

不确定,但是你应该能够通过在settings.xml中设置一个默认的活动配置文件来做一些事情

看到

看到http://maven.apache.org/guides/introduction/introduction-to-profiles.html

在我的情况下,“settings.xml”解决方案不起作用,所以我使用这个命令来下载所有的源代码:

mvn dependency:sources

你也可以将它与其他maven命令一起使用,例如:

mvn clean install dependency:sources -Dmaven.test.skip=true

要下载所有文档,使用以下命令:

mvn dependency:resolve -Dclassifier=javadoc

正如@xecaps12所说,最简单/有效的方法是改变你的Maven设置文件(~/.m2/settings.xml),但如果它是一个默认的设置,你也可以这样设置

<profile>
<id>downloadSources</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>

我使用Maven 3.3.3,无法获得默认配置文件在用户或全局settings.xml文件中工作。

作为一种变通方法,你也可以在你的pom.xml文件中添加一个额外的构建插件。

<properties>
<maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
</properties>
<build>
<plugins>
<!-- Download Java source JARs. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

回答谷歌的人

Eclipse中,你可以手动下载javadoc来源

要做到这一点,右键单击项目并使用

  • Maven→下载JavaDoc
  • Maven→下载来源

只是整合和准备了一个命令来解决源代码和文档下载…

mvn dependency:sources dependency:resolve -Dclassifier=javadoc

NetBeans上: 打开你的项目资源管理器->依赖项->[file.jar]右键单击->下载Javadoc

只需修改文件mvn(或mvn.cmd如果在windows),并添加任何你需要的命令行开关(如其他答案所述)。如果你不想修改安装文件(我建议这样做),可以创建一个mymvn(或mymvn.cmd)包装器,使用参数调用常规的mvn

我必须使用KeyStore来下载jar。如果您有任何与证书相关的问题,您可以使用以下方法:

mvn clean install dependency:sources -Dmaven.test.skip=true -Djavax.net.ssl.trustStore="Path_To_Your_KeyStore"
如果你想知道如何创建密钥库,这是一个非常好的链接: 在代理后使用Maven和SSL的问题 < / p >

在Netbeans中,您可以指示Maven在每个打开的项目上检查javadoc:

Tools | Options | Java图标| Maven选项卡| Dependencies类别| Check Javadoc下拉设置为Every Project Open

关闭并重新打开Netbeans,您将在状态栏中看到Maven下载javadocs。

对于依赖级的源代码(pom.xml),您可以添加:

<classifier>sources</classifier>

为了跟踪kevinarpe的答案,这将同时执行sources和Javadocs:

    <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<goals>
<goal>sources</goal>
<goal>resolve</goal>
</goals>
</execution>
</executions>
<configuration>
<classifier>javadoc</classifier>
</configuration>
</plugin>
</plugins>
</build>

对于intellij用户,在pom.xml文件中,右键单击任意位置并选择Maven ->下载源代码和文档。