Maven – Always download sources and javadocs
JavaMavenJava Problem Overview
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.
Java Solutions
Solution 1 - Java
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>
Solution 2 - Java
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
Solution 3 - Java
Just consolidating and prepared the single command to address source and docs download...
mvn dependency:sources dependency:resolve -Dclassifier=javadoc
Solution 4 - Java
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
Solution 5 - Java
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>
Solution 6 - Java
On NetBeans : open your project explorer->Dependencies->[file.jar] rightclick->Download Javadoc
Solution 7 - Java
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>
Solution 8 - Java
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.
Solution 9 - Java
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>
Solution 10 - Java
I think it can be done per plugin. See http://books.sonatype.com/mvnref-book/reference/_configuring_maven_plugins.html">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 :-).
Solution 11 - Java
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.
Solution 12 - Java
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
Solution 13 - Java
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: https://stackoverflow.com/questions/25911623/problems-using-maven-and-ssl-behind-proxy
Solution 14 - Java
For the sources on dependency level ( pom.xml) you can add :
<classifier>sources</classifier>
Solution 15 - Java
For intellij users, inside the pom.xml file, right click anywhere and select Maven -> Download sources and Documentation.