How to download sources for a jar with Maven?

2020 Update:

The maven dependency plugin should be used whit the dependency:sources goal:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.1.1</version>
    <executions>
      <execution>
        <id>download-sources</id>
        <goals>
          <goal>sources</goal>
        </goals>
        <configuration>
        </configuration>
      </execution>
    </executions>
  </plugin>

This can also be run from the command line as:

mvn dependency:sources -Dsilent=true

Executing mvn dependency:sources will force maven to download all sources of all jars in the project, if the sources are available (are uploaded in the repository where the artifact is hosted). If you want to download javadoc the command is mvn dependency:resolve -Dclassifier=javadoc

Deprecated:

It's also possible to create a profile in your settings.xml file and include the following properties:
<properties>
  <downloadSources>true</downloadSources>
  <downloadJavadocs>true</downloadJavadocs>
</properties>

mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc

if it does not have sources it should say something like

[INFO] The following files have NOT been resolved:
[INFO]    com.oracle:ojdbc6:java-source:sources:12.1.0.1
[INFO]    javax:javaee-api:java-source:sources:6.0

Tags:

Java

Maven

Jar