Integrate Maven with Jenkins

Search in Google:

download maven
and copy the Binary tar.gz archive link, download it to /opt with wget, extract and rename to maven for simplicity:
cd /opt
wget https://dlcdn.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz
tar xvf apache-maven-3.9.6-bin.tar.gz
mv apache-maven-3.9.6 maven
Try to execute binary:
cd maven/bin/
./mvn -version
Get JVM path:
find / -name jvm
Usually it is under /usr/lib/jvm:
$ ls -la /usr/lib/jvm
java-11-openjdk-11.0.20.0.8-1.amzn2.0.1.x86_64
This is the full path:
/usr/lib/jvm/java-11-openjdk-11.0.20.0.8-1.amzn2.0.1.x86_64
Other variables are:
M2_HOME=/opt/maven
M2=/opt/maven/bin
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.20.0.8-1.amzn2.0.1.x86_64
Under /root/.bash_profile, add/modify the following lines:
M2_HOME=/opt/maven
M2=/opt/maven/bin
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.20.0.8-1.amzn2.0.1.x86_64
PATH=$PATH:$HOME/bin:$JAVA_HOME:$M2_HOME:$M2
Source the profile:
. /root/.bash_profile
Try again to execute the mvn binary, it should succeed:
mvn -version
Install the Jenkins plugins Maven Integration and GitHub.
Go to Manage Jenkins -> Tools and add:
JDK
Name - Java 11
JAVA_HOME - /usr/lib/jvm/java-11-openjdk-11.0.20.0.8-1.amzn2.0.1.x86_64
you may get warnings, just use the path from previous steps and ignore them

Maven
Name - maven 3.9.6
MAVEN_HOME - /opt/maven

Do not use Install automatically in both cases.

Create a new Item as Maven Project
Source code management - Git, use: https://github.com/ravdy/hello-world.git
Build - Goals and options: clean package

And build it. You should get SUCCESS