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


当前回答

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

mvn dependency:sources dependency:resolve -Dclassifier=javadoc

其他回答

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

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

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

<classifier>sources</classifier>

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

mvn dependency:sources

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

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

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

mvn dependency:resolve -Dclassifier=javadoc

我使用Maven 3.3.3,无法获得默认配置文件在用户或全局设置.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>

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