NARESH IT COURSE - DEVOPS CHAPTER - MAVEN
MAVEN
Build Management :
S
● Build Management refers to the process of converting raw source code into a
TE
distributable package after being tested and validated.
● Maven is one of Build Management tools
● Technically, Build refers to syntax check in source code.
O
N
Advantages of Build tool :
● Purpose – to build the code.
PS
● Builds are done in SDLC to identify bugs at early stage of life cycle
● Eliminate human errors
O
Build tools :
● MSBuild
● Ant
EV
● nAnt
D
● Maven
● SBT
AR
● Gulp
● Gradle etc
Maven build tool :
M
● Apache maven is an advanced project management tool for java software
KU
projects which is based on POM (project object model).
● It uses POM (project object model) file to manage project’s build, dependency
and documentation.
● The most powerful features of maven are to download the project
AM
dependency libraries automatically and to create the right project structure.
● Introduced in 2002 by Apache
● Open source
● Can build any java framework
KR
● Important configuration file is : [Link]
Features of Maven :
VI
● Open source
● Generate document
● Generate reports
thumuvikram@[Link] VIKRAM KUMAR SIR NOTES 1
NARESH IT COURSE - DEVOPS CHAPTER - MAVEN
● Project management tool
● Follows POM Model
● Does builds and runs test cases
S
TE
Architecture of maven :
O
N
PS
O
EV
D
Maven – Installation, Configuration, verification :
AR
1. visit official site of Maven, web site : [Link]
M
2. go to downloads, download binary zip - [Link]
KU
3. Unzip it to c:\programfiles\
4. Need to create Configure environment variables
AM
- go to system properties, go to advanced tab,
- Under system variables. Please create below -
KR
1. MAVEN_HOME C:\Program Files\apache-maven-3.6.3\bin
2. M2_HOME C:\Program Files\apache-maven-3.6.3\bin
VI
6. Then open command prompt, and verify using below command
thumuvikram@[Link] VIKRAM KUMAR SIR NOTES 2
NARESH IT COURSE - DEVOPS CHAPTER - MAVEN
mvn --version
S
TE
Follow below steps to configure Maven in Jenkins
1. Open Jenkins
O
2. open Manage Jenkins --> open " Global Tool configuration"
N
- need to configure maven
PS
MAVEN_HOME
Maven Life-Cycle Phases :
O
Phase EV Description
Validate the project is correct and all necessary information is
D
validate
available.
AR
compile It compiles the source code of the project.
M
Tests the compiled source code using a suitable testing
Test
framework.
KU
This phase take the compiled code and creates the JAR/WAR
package
package as mentioned in the packaging in [Link].
AM
install This phase installs the package in local maven repository.
KR
Deploy This phase copies the final package to the remote repository.
VI
thumuvikram@[Link] VIKRAM KUMAR SIR NOTES 3
NARESH IT COURSE - DEVOPS CHAPTER - MAVEN
Maven Project Structure :
S
TE
O
N
PS
O
EV
Maven repositories:
D
● Maven repositories are directories of packaged JAR files with extra
meta-data.
AR
● The meta-data is represented by POM files.
● A repository contains all the project jars, library jar, plugins and any other
project specific artifacts.
M
Types of maven repository:
KU
1. Local Repository
2. Central Repository
3. Remote Repository
AM
1. Maven Local Repository:
KR
● Maven local repository is a directory on the developer’s machine.
VI
● It gets created when we run any maven command for the first time.
thumuvikram@[Link] VIKRAM KUMAR SIR NOTES 4
NARESH IT COURSE - DEVOPS CHAPTER - MAVEN
● It contains all the dependencies (downloaded by maven) like library jars,
plugin jars etc.
● Default location of maven local repository is user-home/.m2 directory.
● We can change the default location of maven local repository by changing
S
the [Link] file. It is located in MAVEN_HOME/conf/[Link].
TE
<settings>
O
<localRepository>
N
/ /Set desired location
</localRepository>
</settings>
PS
2. Maven Central Repository:
O
● Maven central repository is created by the apache maven community itself.
● It contains a lot of commonly used libraries.
EV
● By default Maven looks in this central repository for any dependencies
needed but not found in your local repository.
D
Maven central repository path: [Link]
3. Maven Remote Repository:
AR
● Maven remote repository is a repository on a web server.
● A remote repository can be located anywhere on the internet or inside a local
M
network.
● We can configure a remote repository in the POM file.
KU
● We have to put the following XML elements right after the element:
<repositories>
<repository>
AM
<id>[Link]</id>
<url>https://[Link]/maven2/lib</url>
</repository>
KR
</repositories>
VI
SAMPLE PROJECT TO BUILD USING MAVEN :
thumuvikram@[Link] VIKRAM KUMAR SIR NOTES 5
NARESH IT COURSE - DEVOPS CHAPTER - MAVEN
1. Open Jenkins
2. click on new item
S
3. give name to project and select Freestyle option
TE
4. We have to now configure the project
- code repo link
O
[Link]
N
- setup scm
PS
select git, put URL of Repo, enter credentials, select branch
- setup build trigger
O
- choose the build
"Invoke top-level Maven Targets",
EV
D
select the maven version,
enter goals
AR
5. finally save configurations
M
KU
How to check results of build :
Method 1 : Using build history from dashboard menu
● it shows the data of build history, select the appropriate project and click on
AM
console output
Method 2: open the workspace of the project, select the build number from build
KR
history. and click on console output
VI
thumuvikram@[Link] VIKRAM KUMAR SIR NOTES 6