![](/img/trans.png)
[英]How to download sources for an specific JAR dependency of a Maven project
[英]How to download sources for a jar with Maven?
在我的项目中,我使用的是通过 Maven 提供的 JAR 文件。 但是 Maven 给我的只是这个 jar - 没有 javadocs 也没有资源。 按“下载源”没有效果:Eclipse 仍然没有找到 jar 的源。
这取决于什么? 存储库应该自动提供源吗?
可能我需要在 POM 中写一些东西来指示 Maven 下载源代码?
我目前的pom如下:
<repositories>
<repository>
<id>xuggle repo</id>
<url>http://xuggle.googlecode.com/svn/trunk/repo/share/java/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>xuggle</groupId>
<artifactId>xuggle-xuggler</artifactId>
<version>5.3</version>
<type>rar</type>
</dependency>
</dependencies>
为什么 Maven 没有说任何关于它的源下载失败的评论?
2020 更新:
Maven 依赖插件应该与dependency:sources
一起使用dependency:sources
目标:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>download-sources</id>
<goals>
<goal>sources</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
这也可以从命令行运行:
mvn dependency:sources -Dsilent=true
弃用:
执行 mvn dependency:sources
将强制 maven 下载项目中所有 jars 的所有源,如果源可用(上传到托管工件的存储库中)。如果你想下载 javadoc 命令是mvn dependency:resolve -Dclassifier=javadoc
还可以在 settings.xml 文件中创建配置文件并包含以下属性:
<properties> <downloadSources>true</downloadSources> <downloadJavadocs>true</downloadJavadocs> </properties>
mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc
如果它没有来源,它应该说类似
[INFO] The following files have NOT been resolved:
[INFO] com.oracle:ojdbc6:java-source:sources:12.1.0.1
[INFO] javax:javaee-api:java-source:sources:6.0
最好不要依赖 Eclipse 插件,因为它已被弃用。 使用downloadSources
和downloadJavadocs
属性对我不起作用。 上面发布的有关使用依赖项插件词的答案。 但是,您可能希望自动下载源代码和 javadoc。 此外,您可能希望始终创建一个源 jar 和一个 javadoc jar。 把它放在你项目的 pom 中。 如果您使用模块,请放入您的父 pom。
<build>
<plugins>
<!-- download sources and javadoc -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>download-sources</id>
<goals>
<goal>sources</goal>
</goals>
</execution>
<execution>
<id>download-javadoc</id>
<configuration>
<classifier>javadoc</classifier>
</configuration>
<goals>
<goal>resolve</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Always create javadoc jar. -->
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<executions>
<execution>
<id>attach-javadoc</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Always create source jar. -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
在 Eclipse 中,右键单击您的项目,然后单击Maven>Download Sources
再次Maven>Download Sources
Maven>Download Javadoc
您还可以使用以下命令下载target/dependencies
下的源:
mvn -Dclassifier=sources dependency:copy-dependencies
源代码/javadoc jar 可能没有提供,也不在存储库中——没有什么需要存在源/javadoc jar。
扩展@hovanessyan 的回答。
Maven 的 settings.xml 中用于启用 downloadSources 和 downloadJavadocs 的基本配置文件将如下所示。 例如,配置文件 ID 是下载源
<!-- add the profile under profiles section -->
<profile>
<id>downloadSources</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
<!-- activate the profile under activeProfiles section -->
<activeProfiles>
<activeProfile>downloadSources</activeProfile>
</activeProfiles>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.