有人知道是否可以在Maven存储库中找到源jar吗?
当前回答
下载任何工件使用
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只下载项目依赖项的源代码,不下载插件源代码,也不下载插件内部定义的依赖项的源代码。
其他回答
根据在Eclipse (Kepler)中查看Maven控制台,如果您试图在编辑器中从上述Maven依赖项打开一个类,而您还没有下载Maven依赖项的源代码,则将自动下载Maven依赖项的源代码。当您不想为所有依赖项获取源代码,但又不知道需要哪些依赖项时(而且您正在使用Eclipse),这是非常方便的。
我最终使用了@GabrielRamierez的方法,但接下来将使用@PascalThivent的方法。
要下载某些特定的源代码或javadoc,我们需要包括GroupIds -它是一个逗号分隔的值,如下所示
mvn dependency:sources -DincludeGroupIds=com.jcraft,org.testng -Dclassifier=sources
注意,分类器不是用逗号分隔的,要下载javadoc,我们需要使用分类器javadoc再次运行上述命令
mvn dependency:sources -DincludeGroupIds=com.jcraft,org.testng -Dclassifier=javadoc
如果您正在使用Eclipse,我建议同时下载源代码和第三方库的Javadocs。
右键点击项目和下载两个截图如下。
下载Javadocs意味着通常可以从第三方库中获得方法的上下文帮助,其中包含有用的参数描述等。如果你不太了解图书馆,这是很重要的。在某些情况下,我发现当源代码不可用时,Javadocs是可用的。
如果你知道groupId和aritifactId,你可以像这样生成下载url。
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
http://central.maven.org/maven2/ch/qos/logback/logback-classic/
你会得到一个像这样的页面,选择你需要的版本,只是享受它!
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