[英]Maven – Always download sources and javadocs
有没有一种方法可以配置 maven 以始终下载源代码和 javadocs? 每次都指定-DdownloadSources=true -DdownloadJavadocs=true
(这通常伴随着运行 mvn compile 两次,因为我忘记了第一次)变得相当乏味。
打开您的 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>
就我而言,“settings.xml”解决方案不起作用,因此我使用此命令来下载所有源:
mvn dependency:sources
您还可以将它与其他 Maven 命令一起使用,例如:
mvn clean install dependency:sources -Dmaven.test.skip=true
要下载所有文档,请使用以下命令:
mvn dependency:resolve -Dclassifier=javadoc
只是整合并准备了单个命令来解决源代码和文档下载...
mvn dependency:sources dependency:resolve -Dclassifier=javadoc
来自 Google 的人的回答
在Eclipse 中,您可以手动下载javadoc和源代码。
为此,请右键单击项目并使用
我正在使用 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>
在NetBeans 上:打开您的项目资源管理器->依赖项->[ file.jar ] 右键单击->下载 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 书中的这一章。
您也许可以配置依赖项插件来下载源代码(即使我自己还没有尝试过:-)。
在 Netbeans 中,您可以指示 Maven 在每个打开的项目上检查 javadoc:
Tools
| Options
| Java
图标 | Maven
选项卡 | Dependencies
类 | Check Javadoc
下拉设置为Every Project Open
。
关闭并重新打开 Netbeans,您将在状态栏中看到 Maven 下载 javadocs。
要跟进来自kevinarpe的答案,这对来源和 Javadoc 都有影响:
<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>
只需修改文件mvn
(或mvn.cmd
如果在 Windows 中)并添加您需要的任何命令行开关(如其他答案所述)。 如果您不想修改安装文件(我建议这样做),请创建一个mymvn
(或mymvn.cmd
)包装器,该包装器使用参数调用常规mvn
。
不确定,但您应该可以通过在 settings.xml 中设置默认活动配置文件来做一些事情
看
见http://maven.apache.org/guides/introduction/introduction-to-profiles.html
我不得不使用 KeyStore 来下载 Jars。 如果您有任何与证书相关的问题,您可以使用这种方法:
mvn clean install dependency:sources -Dmaven.test.skip=true -Djavax.net.ssl.trustStore="Path_To_Your_KeyStore"
如果你想知道如何创建 KeyStores,这是一个很好的链接: Problems using Maven and SSL behind proxy
对于依赖级别 (pom.xml) 上的源,您可以添加:
<classifier>sources</classifier>
对于 intellij 用户,在 pom.xml 文件中,右键单击任意位置并选择 Maven -> 下载源代码和文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.