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.

- 8,484
- 4
- 40
- 52

- 18,650
- 16
- 58
- 102
-
Is this for the eclipse plugin? You shouldn't have to run that very often anyway... – sjr Apr 25 '11 at 17:04
-
2No, it is for the command line program. I don't have to run it very often, but it would be great if I had to run it never! – schmmd Apr 25 '11 at 17:22
-
1What is the command line? This is when you do `mvn eclipse:eclipse` right? – sjr Apr 25 '11 at 17:44
-
15@sjr, yes in order to download sources and javadocs one can execute `mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true` – Yuriy Nakonechnyy May 16 '13 at 17:30
-
2I think this question still is **not** answered. The accepted answer is related to Eclipse plugin only. @AlexisGamarra's answer is the closest but does not solve the "persistence" of the solution - it does not set Maven to do it *always* whenever you run *mvn install*. – Honza Zidek Dec 14 '17 at 10:20
15 Answers
Open your settings.xml file ~/.m2/settings.xml
(create it if it doesn't exist). Add a section with the properties added. Then make sure the activeProfiles includes the new profile.
<settings>
<!-- ... other settings here ... -->
<profiles>
<profile>
<id>downloadSources</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>downloadSources</activeProfile>
</activeProfiles>
</settings>
Edit: As mentioned by Jingguo Yao, this works with Eclipse IDE only - the same can also be configured in your IDE of choice. In Elcipse via Window -> Preferences -> Maven menu, though this probably has to done at every workspace level and for fresh Eclipse installations.
Alternatively configure the maven-dependency-plugin in your pom.xml in a separate profile and run it as required - keeping it in the main build will lead to build times (needlessly elongating (not to mention space) at places like your build nodes that don't need either sources or java docs. Preferable this should configured in some org or division parent pom.xml, otherwise it has be repeated everywhere in different places
-
6I'm trying these profile properties in Maven 2.2.1 and 3.0.2 and they don't work. The target repository is Archiva. Any suggestions on what else can be tried? I've also tried using dependency:sources goal. Thanks – jmend Sep 03 '12 at 19:28
-
21Moreover, in Eclipse you can just go to Preferences -> Maven (No subcategory). There, you can check "Download artifact Sources/JavaDocs". However, sometimes Eclipse doesn't want to create that file manually (happened to me in Luna). In that case - go there, paste this answer wrapped in settings tags and tell Eclipse to re-load it, and it should work. – Andrei Bârsan Apr 08 '14 at 13:28
-
9This worked for me: in Eclipse go to Preferences -> Maven (No subcategory). Check - "Download artifact Source" - "Download artifact JavaDocs" - "Update Maven projects on startup" (just because I can't find the manual way) Then restart Eclipse. Done – Dirk May 03 '14 at 22:41
-
In Eclipse, in the Maven depencies you can right-click the jar and you have access to a menu : download Sources, JavaDoc, ... So you can do it on a need basis. – Rudy Vissers Jun 19 '15 at 13:22
-
7
-
Eclipse Mars; right-click on a maven project, on menu go to 'Maven' -> 'Download JavaDoc'. Your project will get rebuilt. cheers – Clocker Jul 15 '16 at 02:42
-
12This should **not** be the accepted answer! As @JingguoYao stated, it only affects the Maven Eclipse plugin. The original question was not bound to Eclipse, but rather to the Maven itself. – Honza Zidek Dec 14 '17 at 10:10
-
1
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

- 36,653
- 12
- 122
- 207

- 4,362
- 1
- 33
- 23
-
4I think this question still is **not** answered. The accepted answer is related to Eclipse plugin only. Your answer is the closest but does not solve the "persistence" of the solution - it does not set Maven to do it *always* whenever you run *mvn install*. – Honza Zidek Dec 14 '17 at 10:20
Just consolidating and prepared the single command to address source and docs download...
mvn dependency:sources dependency:resolve -Dclassifier=javadoc

- 4,092
- 1
- 44
- 64

- 5,242
- 1
- 18
- 13
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

- 839
- 2
- 9
- 12
-
4And in IDEA you can right click the Module, and under the Maven menu, there's an option to download sources and/or documentation – forresthopkinsa May 24 '17 at 19:41
-
@Betlista read first line of the post. Lots of people go from google to here looking for something else. But end up going in here, even with different keywords – Ghandhikus Dec 28 '18 at 20:55
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>

- 20,319
- 26
- 127
- 154
On NetBeans : open your project explorer->Dependencies->[file.jar] rightclick->Download Javadoc

- 1,058
- 12
- 17
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>

- 919
- 7
- 22
-
2This doesn't actually work, you're just declaring unused global properties. I believe the mythical solution came from the `maven-eclipse-plugin`: http://maven.apache.org/plugins/maven-eclipse-plugin/examples/attach-library-sources.html – inanutshellus Sep 07 '16 at 16:29
-
-
1The "resolved" version doesn't work either. (I made the same comment there, too, but have removed it temporarily while I confer with you.) So - are you saying your answer (and thus the resolved answer) actually works for you?? I mean, 159 people uploaded that wrong-or-outdated answer, so clearly it works for someone. If it works as you say, then I'm doing something wrong, as are the several people on the resolved answer in its comments and I'd *love* to learn that and get that working. – inanutshellus Sep 08 '16 at 16:28
-
I suppose those global var are checked by eclipse plugin when you are actually developing with eclise. the source fetching is done by eclipse and not by maven on command line. – Jonatan Cloutier Nov 29 '16 at 14:44
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.

- 2,920
- 1
- 35
- 35
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>

- 5,363
- 13
- 61
- 106
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.

- 7,651
- 27
- 37
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 :-).

- 3,710
- 2
- 35
- 45
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

- 222
- 1
- 3
-
-
10You should really copy the relevant parts from the link into your answer, just in case the URL breaks. – Duncan Jones Jan 21 '13 at 08:08
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

- 991
- 1
- 13
- 27
For the sources on dependency level ( pom.xml) you can add :
<classifier>sources</classifier>

- 1,340
- 15
- 23
For intellij users, inside the pom.xml file, right click anywhere and select Maven -> Download sources and Documentation.

- 591
- 8
- 12