I'm using Maven Javadoc Plugin like this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
I have multiple JDK versions installed and want to be able to build a project with any of them. The above configuration works fine with Java 8, but it fails with Java 11 with the following error
Failed to execute goal
org.apache.maven.plugins:maven-javadoc-plugin:3.1.1:jar
(attach-javadocs) on project ...: MavenReportException: Error while
generating Javadoc: Unable to find javadoc command: The environment
variable JAVA_HOME is not correctly set.
The obvious solution is to set JAVA_HOME. But as I mentioned, I have multiple versions of JDK, so reconfiguring JAVA_HOME every time I want to use another version wouldn't be convenient at all.
Another solution (from Unable to find javadoc command - maven) is to add the following configuration to the plugin:
<configuration>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</configuration>
This makes it work with Java 11, but breaks Java 8 because the javadoc location is ${java.home}/../bin/javadoc in that case.
Ideally I always want to use javadoc from the directory where the java executable that Maven uses is, but I haven't found a way to do it with Maven Javadoc Plugin.
Maven profiles may be able to help.
Add something like this to your POM.
<profiles>
<profile>
<id>jdk-8-config</id>
<activation>
<jdk>1.8</jdk>
</activation>
<properties>
<javadocExecutable>${java.home}/../bin/javadoc</javadocExecutable>
</properties>
</profile>
<profile>
<id>jdk-11-config</id>
<activation>
<jdk>11</jdk>
</activation>
<properties>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</properties>
</profile>
</profiles>
JDK ranges are also possible, read more on those in the linked doc.
Maven will pick up the version of Java being used to run itself, activate the correct profile, and define the property correct.
A caveat - typically we build with JAVA_HOME set, or via Jenkins which can be configured to define JAVA_HOME per job. This approach works well in those cases.
You could also investigate Maven toolchains. I have no experience with those, other than reading they help make it easier to define tool locations on various machines.
Related
I am trying to build a Hudson plugin I've modified and it requires jdk1.6. This is fine, but I don't see how I can tell maven where the different jdk is. I've found few mentions on the internet but they don't seem to apply to me. Some suggest adding some config to .m2/settings.xml but I don't have a settings.xml. Plus, I don't want to use 1.6 for all maven builds.
One kink is I am using mvn in cygwin, if that matters at all. It appears I should be able to make the specification in the project pom file, but the existing pom is pretty bare.
So bottom line is, is there a way to specify a jdk for a single invocation of maven?
So bottom line is, is there a way to specify a jdk for a single invocation of maven?
Temporarily change the value of your JAVA_HOME environment variable.
Seems that maven now gives a solution here : Compiling Sources Using A Different JDK
Let's say your JAVA_HOME points to JDK7 (which will run maven processes)
Your pom.xml could be :
<build>
<plugins>
<!-- we want JDK 1.6 source and binary compatiblility -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- ... -->
<!-- we want sources to be processed by a specific 1.6 javac -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_1_6_HOME}/bin/javac</executable>
<compilerVersion>1.3</compilerVersion>
</configuration>
</plugin>
</plugins>
</build>
If your developpers just add (and customize) the following lines in their settings.xml, your pom will be platform independant :
<settings>
[...]
<profiles>
[...]
<profile>
<id>compiler</id>
<properties>
<JAVA_1_4_HOME>C:\Program Files\Java\j2sdk1.4.2_09</JAVA_1_4_HOME>
<JAVA_1_6_HOME>C:\Program Files\Java\j2sdk1.6.0_18</JAVA_1_6_HOME>
</properties>
</profile>
</profiles>
[...]
<activeProfiles>
<activeProfile>compiler</activeProfile>
</activeProfiles>
</settings>
compile:compile has a user property that allows you to specify a path to the javac.
Note that this user property only works when fork is true which is false by default.
$ mvn -Dmaven.compiler.fork=true -Dmaven.compiler.executable=/path/to/the/javac compile
You might have to double quote the value if it contains spaces.
> mvn -Dmaven.compiler.fork=true -Dmaven.compiler.executable="C:\...\javac" compile
See also Maven custom properties precedence.
As u said "Plus, I don't want to use 1.6 for all maven builds."....So better I will say modify your pom file and specify which jdk version to use.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.9</source>
<target>1.9</target>
</configuration>
</plugin>
</plugins>
</build>
It will ensure that your particular project uses that version of jdk.
I say you setup the JAVA_HOME environment variable like Pascal is saying:
In Cygwin if you use bash as your shell should be:
export JAVA_HOME=/cygdrive/c/pathtothejdk
It never harms to also prepend the java bin directory path to the PATH environment variable with:
export PATH=${JAVA_HOME}/bin:${PATH}
Also add maven-enforce-plugin to make sure the right JDK is used. This is a good practice for your pom.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>1.6</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Please, see Maven Enforcer plugin – Usage.
If you have installed Java through brew in Mac then chances are you will find your Java Home Directory here:
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
The next step now would be to find which Java Home directory maven is pointing to. To find it type in the command:
mvn -version
The fields we are interested in here is:
Java version and runtime.
Maven is currently pointing to Java 13. Also, you can see the Java Home path under the key runtime, which is:
/usr/local/Cellar/openjdk/13.0.2+8_2/libexec/openjdk.jdk/Contents/Home
To change the Java version of the maven, we need to add the Java 8 home path to the JAVA_HOME env variable.
To do that we need to run the command:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
in the terminal.
Now if we check the maven version, we can see that it is pointing to Java 8 now.
The problem with this is if you check the maven version again in the new terminal, you will find that it is pointing to the Java 13. To avoid this I would suggest adding the JAVA_HOME variable in the ~/.profile file.
This way whenever your terminal is loading it will take up the value you defined in the JAVA_HOME by default. This is the line you need to add in the ~/.profile file:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
You can open up a new terminal and check the Maven version, (mvn -version) and you will find it is pointing to the Java 8 this time.
I know its an old thread. But I was having some issues with something similar to this in Maven for Java 8 compiler source. I figured this out with a quick fix mentioned in this article thought I can put it here and maybe can help others:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Maven uses variable $JAVACMD as the final java command, set it to where the java executable is will switch maven to different JDK.
You could also set the JDK for Maven in a file in your home directory ~/.mavenrc:
JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home'
This environment variable will be checked by the mvn script and used when present:
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
https://github.com/CodeFX-org/mvn-java-9/tree/master/mavenrc
Hudson also allows you to define several Java runtimes, and let you invoke Maven with one of these. Have a closer look on the configuration page.
Yet another alternative to manage multiple jdk versions is jEnv
After installation, you can simply change java version "locally" i.e. for a specific project directory by:
jenv local 1.6
This will also make mvn use that version locally, when you enable the mvn plugin:
jenv enable-plugin maven
I update my ~/.m2/settings.xml
<settings>
<profiles>
<profile>
<id>j8</id>
<profile>
<id>j8</id>
<properties>
<maven.compiler.fork>true</maven.compiler.fork>
<maven.compiler.executable>${env.JAVA_HOME8}/bin/javac.exe</maven.compiler.executable>
</properties>
</profile>
<profile>
<id>j11</id>
<properties>
<maven.compiler.fork>true</maven.compiler.fork>
<maven.compiler.executable>${env.JAVA_HOME11}/bin/javac.exe</maven.compiler.executable>
</properties>
</profile>
</profiles>
<settings>
For build with Java8 I run mvn with properties:
mvn compile -Pj8
and for Java 11
mvn compile -Pj11
If nothing else works and even after you set JAVA_HOME to a correct path, check if there is no override of the JAVA_HOME path in <user>/.mavenrc!
As a further tip, the mvn file is a bash script (on Linux).. so if necessary you can inspect the source [and change it].
I had build problem with maven within Eclipse on Windows 7.
Though I observed mvn build was running just fine from command line.
mvn -T 5 -B -e -X -U -P test clean install -Dmaven.surefire.debug --settings ..\..\infra-scripts\maven-conf\settings.xml > output.log
Eclipse was considering as default JVM a JRE installation instead of JDK so it was failing on compilation.
I added to eclipse.ini following line:
-vm
C:\Program Files (x86)\Java\jdk1.8.0_25\bin
Also when starting from eclipse I used in "Goals" section following list:
-T 5 -B -e -X -U -P test clean install -Dmaven.surefire.debug --settings ..\..\infra-scripts\maven-conf\settings.xml
Compilation error got solved.
For Java 9 :
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
I'm not very experienced with Maven and while experimenting with multi-module project I started wondering how can I specify Java version for all my child modules in parent Maven pom. Until today I was using just:
<properties>
<java.version>1.8</java.version>
</properties>
...but when researching I found that you can also specify Java version in Maven compiler plugin, like that:
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
And then wrap this into plugin management tag to enable child poms usage of this. So the first question is this:
What are the differences beetwen setting Java version in properties and in Maven compiler plugin?
I couldn't find clear answer but in process of researching I found that you can also specify Java version in this way:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
...which suggest that compiler plugin is there even if I don't explicit declare it. Running mvn package outputs with
maven-compiler-plugin:3.1:compile (default-compile) # testproj ---
...and some other plugins that I didn't declare.
So are those plugins default, hidden part of Maven pom? Are there any differences between setting source/target in properties and in Maven plugin configuration element?
Some other questions are - which way should be used (and when if they are not equal)? Which one is best for multi-module project and what happens if Java version specified in pom is different than version pointed in JAVA_HOME?
How to specify the JDK version?
Use any of three ways: (1) Spring Boot feature, or use Maven compiler plugin with either (2) source & target or (3) with release.
Spring Boot
<java.version> is not referenced in the Maven documentation.
It is a Spring Boot specificity.
It allows to set the source and the target java version with the same version such as this one to specify java 1.8 for both :
1.8
Feel free to use it if you use Spring Boot.
maven-compiler-plugin with source & target
Using maven-compiler-plugin or maven.compiler.source/maven.compiler.target properties are equivalent.
That is indeed :
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
is equivalent to :
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
according to the Maven documentation of the compiler plugin
since the <source> and the <target> elements in the compiler configuration use the properties maven.compiler.source and maven.compiler.target if they are defined.
source
The -source argument for the Java compiler.
NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6. Since 3.9.0 the default value has changed from 1.6 to 1.7
Default value is: 1.7.
User property is: maven.compiler.source.
target
The -target argument for the Java compiler.
NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6. Since 3.9.0 the default value has changed from 1.6 to 1.7
Default value is: 1.6.
User property is: maven.compiler.target.
About the default values for source and target, note that
since the 3.8.0 of the maven compiler, the default values have changed from 1.5 to 1.6.
maven-compiler-plugin with release instead of source & target
The maven-compiler-plugin 3.6 and later versions provide a new way :
org.apache.maven.plugins
maven-compiler-plugin
3.8.0
9
You could also declare just :
<properties>
<maven.compiler.release>9</maven.compiler.release>
</properties>
But at this time it will not work as the maven-compiler-plugin default version you use doesn't rely on a recent enough version.
The Maven release argument conveys release : a new JVM standard option that we could pass from Java 9 :
Compiles against the public, supported and documented API for a
specific VM version.
This way provides a standard way to specify the same version for the source, the target and the bootstrap JVM options.
Note that specifying the bootstrap is a good practice for cross compilations and it will not hurt if you don't make cross compilations either.
Which is the best way to specify the JDK version?
The first way (<java.version>) is allowed only if you use Spring Boot.
For Java 8 and below :
About the two other ways : valuing the maven.compiler.source/maven.compiler.target properties or using the maven-compiler-plugin, you can use one or the other. It changes nothing in the facts since finally the two solutions rely on the same properties and the same mechanism : the maven core compiler plugin.
Well, if you don't need to specify other properties or behavior than Java versions in the compiler plugin, using this way makes more sense as this is more concise:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
From Java 9 :
The release argument (third point) is a way to strongly consider if you want to use the same version for the source and the target.
What happens if the version differs between the JDK in JAVA_HOME and which one specified in the pom.xml?
It is not a problem if the JDK referenced by the JAVA_HOME is compatible with the version specified in the pom but to ensure a better cross-compilation compatibility think about adding the bootstrap JVM option with as value the path of the rt.jar of the target version.
An important thing to consider is that the source and the target version in the Maven configuration should not be superior to the JDK version referenced by the JAVA_HOME.
A older version of the JDK cannot compile with a more recent version since it doesn't know its specification.
To get information about the source, target and release supported versions according to the used JDK, please refer to java compilation : source, target and release supported versions.
How handle the case of JDK referenced by the JAVA_HOME is not compatible with the java target and/or source versions specified in the pom?
For example, if your JAVA_HOME refers to a JDK 1.7 and you specify a JDK 1.8 as source and target in the compiler configuration of your pom.xml, it will be a problem because as explained, the JDK 1.7 doesn't know how to compile with.
From its point of view, it is an unknown JDK version since it was released after it.
In this case, you should configure the Maven compiler plugin to specify the JDK in this way :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerVersion>1.8</compilerVersion>
<fork>true</fork>
<executable>D:\jdk1.8\bin\javac</executable>
</configuration>
</plugin>
You could have more details in examples with maven compiler plugin.
It is not asked but cases where that may be more complicated is when you specify source but not target. It may use a different version in target according to the source version. Rules are particular : you can read about them in the Cross-Compilation Options part.
Why the compiler plugin is traced in the output at the execution of the Maven package goal even if you don't specify it in the pom.xml?
To compile your code and more generally to perform all tasks required for a maven goal, Maven needs tools. So, it uses core Maven plugins (you recognize a core Maven plugin by its groupId : org.apache.maven.plugins) to do the required tasks : compiler plugin for compiling classes, test plugin for executing tests, and so for... So, even if you don't declare these plugins, they are bound to the execution of the Maven lifecycle.
At the root dir of your Maven project, you can run the command : mvn help:effective-pom to get the final pom effectively used. You could see among other information, attached plugins by Maven (specified or not in your pom.xml), with the used version, their configuration and the executed goals for each phase of the lifecycle.
In the output of the mvn help:effective-pom command, you could see the declaration of these core plugins in the <build><plugins> element, for example :
...
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
...
You can have more information about it in the introduction of the Maven lifeycle in the Maven documentation.
Nevertheless, you can declare these plugins when you want to configure them with other values as default values (for example, you did it when you declared the maven-compiler plugin in your pom.xml to adjust the JDK version to use) or when you want to add some plugin executions not used by default in the Maven lifecycle.
None of the solutions above worked for me straight away. So I followed these steps:
Add in pom.xml:
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
Go to Project Properties > Java Build Path, then remove the JRE
System Library pointing to JRE1.5.
Force updated the project.
The below steps work for me like charm! so thought to share with everyone.
These are the lines i added in the pom.xml file to work with a basic project. I am using Java 12 (you can replace yours 11, 10, 1.8 etc).
<properties>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
</plugins>
</build>
After changing the pom file please reload your project so that IDE can download/fetch the plugin to the project. (For IntelijIDEA: Right-click on pom.xml -> Go to maven -> Reload project).
please make sure to configure the desire version in your IDE as well.
if you are using IntelliJ idea maven build.
Consider the alternative:
<properties>
<javac.src.version>1.8</javac.src.version>
<javac.target.version>1.8</javac.target.version>
</properties>
It should be the same thing of maven.compiler.source/maven.compiler.target but the above solution works for me, otherwise the second one gets the parent specification (I have a matrioska of .pom)
For NetBeans IDE, changing project properties - (Jersey Service) - Categories > Sources >
Selected 'Source/Binary Format' as 1.8.
I have 2 applications, Apps A uses Java 8 and Apps B uses Java 7.
Furthermore, my company using Jenkins and Java 7.
I need to build Apps A without change the original environment.
Is there any method that I can choose between Java 7 and Java 8 to build an application with Jenkins?
or
Can I choose java version when maven build?
Thank you
Jenkins can manage multiple versions of the Java JDK which can be selected when creating each build job:
https://www.safaribooksonline.com/library/view/jenkins-the-definitive/9781449311155/ch04s05.html
With maven you can specify different build profiles, the profiles can be automatically selected depending on wich JDK you are executing maven targets with. This is an example for that, here activated using jdk 1.4:
<profiles>
<profile>
<activation>
<jdk>1.4</jdk>
</activation>
...
</profile>
</profiles>
Read more about profiles here: http://maven.apache.org/guides/introduction/introduction-to-profiles.html
You can also specify witch buildversion to use with a build plugin like this:
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
</plugins>
[...]
Read more about source and target versions here: https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
By combining these two possible configurations in you pom I think you should be able to set maven to automatically creating the target java version for your liking.
Profiles can use many activation methods to determine what to do so further options are available.
Currently we are working on the big maven project that has about 100 modules, some of them have submodules as well.
Some of modules use Maven Build Number plugin. The project is hosted under subversion.
Recently we started to use git locally in our development team.
After cloning subversion repo and trying to build the Project, we received following well known error:
The svn command failed.
Command output:
svn: ‘.’ is not a working copy
Unfortunately in our case it is not an option to create a new profile or just remove plugin definition from POM (this will follow to messing up hundreds of POM files).
I found the following article http://abstractionextraction.wordpress.com/2012/09/27/git-svn-vs-maven-build-number-plugin/ but honestly, it's not something that I would really like to do...
Is there any smart way to disable this plugin. Like command-line parameter?
I think you may skip failure on obtain revision without change project pom.xml - buildnumber-maven-plugin has option revisionOnScmFailure which you may use like:
mvn -Dmaven.buildNumber.revisionOnScmFailure=no-scm package
In that case value no-scm will be used if scm call was unsuccessful. Off course you may change it and provide any other string.
Per the mojo documentation, you could use the revisionOnScmFailure property.
However, it doesn't have a command line option. You'll have to modify those pom.xml files.
See "Defining Parameters Within a Mojo" in the Maven Java Plugin Development Guide
One approach would be to use a property in your pom to specify the execution phase of the build number plugin, as shown below.
<project>
..
<properties>
<buildnumber.plugin.phase>validate</buildnumber.plugin.phase>
..
</properties>
..
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>${buildnumber.plugin.phase}</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
..
</configuration>
</plugin>
</plugins>
..
</project>
Then provide the property on the command line to disable the plugin, as shown in the following example.
mvn install -Dbuildnumber.plugin.phase=none
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.
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
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
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
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>
On NetBeans :
open your project explorer->Dependencies->[file.jar] rightclick->Download Javadoc
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 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.
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>
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 :-).
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.
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
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
For the sources on dependency level ( pom.xml) you can add :
<classifier>sources</classifier>
For intellij users, inside the pom.xml file, right click anywhere and select Maven -> Download sources and Documentation.