[java] Maven – Always download sources and javadocs

Is there a way I can configure maven to always download sources and javadocs? Specifying -DdownloadSources=true -DdownloadJavadocs=true everytime (which usually goes along with running mvn compile twice because I forgot the first time) becomes rather tedious.

This question is related to java maven

The answer is


For the sources on dependency level ( pom.xml) you can add :

<classifier>sources</classifier>

Just consolidating and prepared the single command to address source and docs download...

mvn dependency:sources dependency:resolve -Dclassifier=javadoc

Answer for people from Google

In Eclipse you can manually download javadoc and sources.

To do that, right click on the project and use

  • Maven -> Download JavaDoc
  • Maven -> Download Sources

To follow up on the answer from kevinarpe this does both sources and 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>

In Netbeans, you can instruct Maven to check javadoc on every project open :

Tools | Options | Java icon | Maven tab | Dependencies category | Check Javadoc drop down set to Every Project Open.

Close and reopen Netbeans and you will see Maven download javadocs in the status bar.


Not sure, but you should be able to do something by setting a default active profile in your settings.xml

See

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


Simply modify file mvn (or mvn.cmd if in windows) and add whatever command line switches you need (as mentioned by other answers). If you don't want to modify the install files (which I'd recommend), create a mymvn (or mymvn.cmd) wrapper that invokes the regular mvn with the parameters.


I had to use KeyStore to Download the Jars. If you have any Certificate related issues you can use this approach:

mvn clean install dependency:sources -Dmaven.test.skip=true -Djavax.net.ssl.trustStore="Path_To_Your_KeyStore"

If you want to know how to create KeyStores, this is a very good link: Problems using Maven and SSL behind proxy


I am using Maven 3.3.3 and cannot get the default profile to work in a user or global settings.xml file.

As a workaround, you may also add an additional build plugin to your pom.xml file.

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

I think it can be done per plugin. See this chapter from the Maven book.

You might be able to configure the dependency plugin to download sources (even though I haven't tried it myself :-).


As @xecaps12 said, the simplest/efficient approach is to change your Maven settings file (~/.m2/settings.xml) but if it is a default settings for you, you can also set it like that

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

In my case the "settings.xml" solution didn't work so I use this command in order to download all the sources:

mvn dependency:sources

You also can use it with other maven commands, for example:

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

To download all documentation, use the following command:

mvn dependency:resolve -Dclassifier=javadoc

On NetBeans : open your project explorer->Dependencies->[file.jar] rightclick->Download Javadoc