有人知道是否可以在Maven存储库中找到源jar吗?
当前回答
如果您想手动找到任何工件的源jar文件,请转到特定工件的maven存储库位置,并在Files中单击“view All”。你可以找到源jar文件。
其他回答
Maven Micro-Tip: Get sources and Javadocs When you're using Maven in an IDE you often find the need for your IDE to resolve source code and Javadocs for your library dependencies. There's an easy way to accomplish that goal. mvn dependency:sources mvn dependency:resolve -Dclassifier=javadoc The first command will attempt to download source code for each of the dependencies in your pom file. The second command will attempt to download the Javadocs. Maven is at the mercy of the library packagers here. So some of them won't have source code packaged and many of them won't have Javadocs. In case you have a lot of dependencies it might also be a good idea to use inclusions/exclusions to get specific artifacts, the following command will for example only download the sources for the dependency with a specific artifactId: mvn dependency:sources -DincludeArtifactIds=guava
来源:http://tedwise.com/2010/01/27/maven-micro-tip-get-sources-and-javadocs/
文档:https://maven.apache.org/plugins/maven-dependency-plugin/sources-mojo.html
在Eclipse中
右键单击pom.xml 选择Run As -> Maven generate-sources 默认情况下,它将在.m2文件夹中生成源代码
Pre-Requisite:
Maven应该使用Eclipse进行配置。
如果您正在使用Eclipse,我建议同时下载源代码和第三方库的Javadocs。
右键点击项目和下载两个截图如下。
下载Javadocs意味着通常可以从第三方库中获得方法的上下文帮助,其中包含有用的参数描述等。如果你不太了解图书馆,这是很重要的。在某些情况下,我发现当源代码不可用时,Javadocs是可用的。
如果一个项目创建了一个项目源代码的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支持高级搜索)。请看这个搜索的例子。
下载任何工件使用
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只下载项目依赖项的源代码,不下载插件源代码,也不下载插件内部定义的依赖项的源代码。