Build Automation using Maven
-
Upload
ankit-gubrani -
Category
Software
-
view
1.678 -
download
2
description
Transcript of Build Automation using Maven
![Page 1: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/1.jpg)
Build Automation With maven(By Ankit Gubrani)
![Page 2: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/2.jpg)
Agenda
q What is maven?q Why maven?q Maven Installation.q How maven works.q The build Lifecycle.q Basics of POM, Profiles, Repositories.q Maven Plugins.q Maven Dependency.q Creating custom maven Plugin.
![Page 3: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/3.jpg)
What is maven ?
![Page 4: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/4.jpg)
Any Idea?
![Page 5: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/5.jpg)
Ok but before that !What is a build tool?
![Page 6: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/6.jpg)
Build Tool
q A build tool is a programming utility that is used whenbuilding a new version of a program.
q Build tools are tools to manage and organise yourbuilds.
![Page 7: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/7.jpg)
![Page 8: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/8.jpg)
Now that you know What Build Tool is. Here is Maven -
![Page 9: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/9.jpg)
Maven
q Maven is a popular open source build tool used primarilyfor Java projects. It was designed to make buildprocess easier task.
q Apart from being a build tool Maven can also managereporting and documentation from a central piece ofinformation.
q It is based on the concept of a project object model(POM).
q Maven is more than just a "build tool" rather is aproject management tool.
![Page 10: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/10.jpg)
Maven provides developers ways to manage following:q Buildsq Documentationq Reportingq Dependenciesq SCMsq Releasesq Distributionq Mailing list
![Page 11: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/11.jpg)
Why Maven if we have other Build tools available ???
![Page 12: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/12.jpg)
Comparison
Here are some of the benefits of using Maven over anyother build (Ant, make etc) :
q Standardized project layout. (Convention overconfiguration unlike ANT)
q Automatic dependency handling.(Ant can't do thisunassisted)
q Large Existing repository.
q Reusability ( through Maven Plugins).
![Page 13: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/13.jpg)
Maven Installation
![Page 14: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/14.jpg)
Installation
q Maven is a Java tool, so you must have Java installed inorder to proceed.
q Follow the instructions on the link for intallation :
http://maven.apache.org/download.cgi#Installation
q Once installation is done type the following command ina terminal or in a command prompt:
mvn –versionIt should print out your installed version of Maven
![Page 15: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/15.jpg)
![Page 16: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/16.jpg)
Maven Build Lifecycle
![Page 17: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/17.jpg)
Lifecycle
q Build Lifecycle is a well defined sequence of phaseswhich define the order in which the goals are to beexecuted. Here phase represents a stage in life cycle.
q When Maven starts building a project, it steps througha defined sequence of phases and executes goals whichare registered with each phase. Maven has followingthree standard lifecycles:
q Cleanq default(or build)q Site
![Page 18: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/18.jpg)
q A Build Lifecycle is Made Up of Phases.
q A Build Phase is Made Up of Plugin Goals.
q A Plugin Goal represents a specific task (finer than abuild phase) which contributes to the building andmanaging of a project.
![Page 19: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/19.jpg)
lPhase-Goal BindinglLifecycle-Phase Binding
![Page 20: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/20.jpg)
POM
![Page 21: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/21.jpg)
lProject Object Model
q POM stands for Project Object Model. It isfundamental Unit of work in Maven.
q It is an XML file. It always resides in the basedirectory of the project as pom.xml.
q The POM contains information about the project andvarious configuration detail used by Maven to build theproject.
![Page 22: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/22.jpg)
lSome of the configuration that can be specified in thePOM are following:
q project dependenciesq pluginsq goalsq build profilesq project versionq developersq mailing list
![Page 23: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/23.jpg)
Maven Repository
![Page 24: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/24.jpg)
q A maven repository is a directory of packaged JAR file withpom.xml file. Maven searches for dependencies in therepositories. There are 3 types of maven repostory :§ Local Repository§ Central Repository§ Remote Repository
q Maven searches for the dependencies in the following order:q Local repository then Central repository then Remote
repository.
![Page 25: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/25.jpg)
q Local Repository :-§ Maven local repository is located in your local
system. It is created by the maven when you runany maven command.
§ By default, maven local repository is%USER_HOME%/.m2 directory. For example:C:\Users\SSS IT\.m2.
q Central Repository :-§ Maven central repository is located on the web. It
has been created by the apache maven communityitself.
§ The path of central repository is:http://repo1.maven.org/maven2 .
![Page 26: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/26.jpg)
q Remote Repository :-
§ Maven remote repository is located on the web.Most of libraries can be missing from the centralrepository such as JBoss library etc, so we need todefine remote repository in pom.xml file.
![Page 27: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/27.jpg)
Build Profile
![Page 28: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/28.jpg)
q A Build profile is a set of configuration values which can beused to set or override default values of Maven build. Usinga build profile, you can customize build for differentenvironments such as Production v/s Developmentenvironments.
q Build profiles are majorly of three types :
§ Per Project :- Defined in the project POM file, pom.xml§ Per User :- Defined in Maven settings xml file
(%USER_HOME%/.m2/settings.xml)§ Global :- Defined in Maven global settings xml file
(%M2_HOME%/conf/settings.xml)
![Page 29: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/29.jpg)
Maven Plugins
![Page 30: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/30.jpg)
q Plugins are the central feature of Maven that allow for thereuse of common build logic across multiple projects.
q Maven is actually a plugin execution framework where everytask is actually done by plugins.
q A plugin generally provides a set of goals and which can beexecuted using following syntax:ü mvn [plugin-name]:[goal-name]
q There are plugins for almost every task in maven like pluginsare used to: create jar files, create war files, compile code,unit test code, create project documentation, and on and on.
![Page 31: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/31.jpg)
q Maven provides following two types of Plugins:
1)Build plugins:- They execute during the build and should beconfigured in the <build/> element of pom.xml .2)Reporting plugins:-They execute during the sitegeneration and they should be configured in the<reporting/> element of the pom.xml .
![Page 32: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/32.jpg)
Archetype
![Page 33: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/33.jpg)
lAn archetype is defined as an original pattern or model fromwhich all other things of the same kind are made.
lMaven provides users,a very large list of different types ofproject templates using concept of Archetype. Maven helpsusers to quickly start a new java project using followingcommand :
mvn archetype:generate
lArchetype is a Maven plugin whose task is to create a projectstructure as per its template. Archetype Plugin allows the userto create a Maven project from an existing template called anarchetype.
Archetype
![Page 34: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/34.jpg)
Now that you know basics of maven,Let's create a maven project
![Page 35: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/35.jpg)
q For creating any project maven provides templates(Archetype),using which one can create by selecting any one archetype fromavailable archetypes.
q To start a new Maven project, use the Maven Archetype plugin fromthe command line. Run the following command :-
§ mvn archetype:generate -DarchetypeGroupId=[Group Id] -DarchetypeArtifactId= [Artifact ID]
q You can search for all archetypes provided by maven at therecentral repository (http://search.maven.org/) and all other 3rdparty archetypes at any remote repository like -http://mvnrepository.com
![Page 36: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/36.jpg)
Demo
![Page 37: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/37.jpg)
Maven Snapshots
![Page 38: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/38.jpg)
q SNAPSHOT is a special version that indicates a currentdevelopment copy.
q Unlike regular versions, Maven checks for a newSNAPSHOT version in a remote repository for every build.
q Snapshot vs Version :-q In case of Version, if Maven once downloaded the mentioned
version say data-service:1.0, it will never try to download anewer 1.0 available in repository. To download the updatedcode, artifact version is be upgraded to 1.1.
q In case of SNAPSHOT, Maven will automatically fetch thelatest SNAPSHOT (data-service:1.0-SNAPSHOT)everytime app-ui team build their project.
![Page 39: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/39.jpg)
Hey did you notice ???What we did till now automated the build
process. And this is called Build Automation using Maven
![Page 40: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/40.jpg)
Auto-Generated Project DocumentationUsing maven
![Page 41: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/41.jpg)
q Team communication is an essential part of anyproject. And wasting time looking for technical projectinformation can be costly and frustrating. Clearly, anyIT project will benefit from having its own dedicatedtechnical Website.
q That's where the Maven site generator steps in. Withlittle effort, you can have a professional-quality, lowmaintenance project Website up and running in no time.
q Documentation is generated by running§ mvn site
![Page 42: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/42.jpg)
Any Questions ?
![Page 43: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/43.jpg)
![Page 44: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/44.jpg)
lAbout Me
.about-me{name: Ankit Gubrani !Sr. AEM Developer;email-id: [email protected];LinkedIn: in.linkedin.com/in/ankitgubrani;twitter: @ankitgubrani90;blog: codebrains.blogspot.in;website : codebrains.co.in;
}
![Page 45: Build Automation using Maven](https://reader034.fdocuments.us/reader034/viewer/2022042715/559c97f11a28ab54298b4875/html5/thumbnails/45.jpg)
Thank YouPlease contact me at : [email protected]