The problem of using multiple maven version, there are problems for either one or another version.
The reason are the following (based on the experience I passed through)
- If one of the versions is set as M2_HOME environment variable, then the other will have an impact on others's in case of running the command. And consequently, the affected versions would throw the following error
In case of using multiple versions of Maven,
(1) Mentioning the JAVA_HOME and the M2_HOME / M2 and MAVEN_OPTS at environment level environment variable.
(2) Do not use the mvn command, since this command is looking for the system's M2_HOME (I don't know why but i wonder why)
(3) At the system Level, DO NOT set the M2_HOME or M3_HOME (for maven3). If you have it, comment out (in linux). As well in the PATH directory. Do not forget to reload the environment variable path.
(4) Manually, run the command by using the direct path of the command. This is in order to verify that the command is working.
/path/to/a/maven-version/bin/mvn -version
(5) At the Pipeline JOB task, use the following command
Command: /bin/sh
Arguments:
-c
/path/to/a/maven-version/bin/mvn clean package.