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


当前回答

为了跟踪kevinarpe的答案,这对sources和Javadocs都做了:

    <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>

其他回答

为了跟踪kevinarpe的答案,这对sources和Javadocs都做了:

    <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 dependency:sources dependency:resolve -Dclassifier=javadoc

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

不确定,但是你应该能够通过在settings.xml中设置一个默认的活动配置文件来做一些事情

See

参见http://maven.apache.org/guides/introduction/introduction-to-profiles.html

正如@xecaps12所说,最简单/有效的方法是更改Maven设置文件(~/.m2/settings.xml),但如果它是您的默认设置,您也可以这样设置

<profile>
  <id>downloadSources</id>
  <activation>
    <activeByDefault>true</activeByDefault>
  </activation>
  <properties>
      <downloadSources>true</downloadSources>
      <downloadJavadocs>true</downloadJavadocs>
  </properties>
</profile>