Topics :-
*Maven Installation and configuration
*Eclipse: Maven plugin
*Maven Selenium Sample Project
*POM.xml
*Build Lifecycle
*Internal and remote repositories
Maven Installation and configuration
1. JDK and JAVA_HOME
Make sure JDK is installed, and “JAVA_HOME” variable is added in Windows environment variable, and point to the JDK folder.
2. Download Apache Maven
Visit this Maven official website, choose a version and click on the download link, e.g
3. Extract It
Extract the downloaded zip file. In this case, we extracted to d driver and renamed the folder, e.g D:\maven.
4. Add MAVEN_HOME
Add a new MAVEN_HOME variable to the Windows environment, and point it to your Maven folder.
5. Add PATH
Update PATH variable, append “Maven bin folder” path, so that you can run the Maven’s command everywhere.
6. Verification
Done, to verify it, in command prompt, type “mvn –version“.
Eclipse: Maven plugin
Open eclipse
Go to -> Help Menu-> Install new software and install Apache Maven plugin <Similar to TestNG>
URL :- http://download.eclipse.org/technology/m2e/releases
Restart eclipse
For the Verification Go to File menu -> New ->MavenProject
Maven Selenium Sample Project Video
Kindly go through the below video.
POM.xml
- Stands for Project Object Model
- Fundamental Unit of Work in Maven.
- XML file.
- Resides in the base directory of the project as pom.xml
Some of the configuration that can be specified in the POM are following:
- Project information
- project dependencies
- plugins
- goals
- build profiles
- project version
- developers
- mailing list
Maven uniquely identifies a project using:
- groupID: Arbitrary project grouping identifier (no spaces or colons)
- artfiactId: Arbitrary name of project (no spaces or colons)
- version: Version of project
Format {Major}.{Minor}.{Maintanence}
Add ‘-SNAPSHOT ‘ to identify in development
GAV Syntax: groupId:artifactId:version
<?xml
version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-training</artifactId>
<groupId>org.lds.training</groupId>
<version>1.0</version>
<packaging>jar</packaging>
</project>
Build Lifecycle
A Build Lifecycle is a well defined sequence of phases which define the order in which the goals are to be executed.
Maven has following three standard lifecycles:
clean
default(or build)
site
Clean Lifecycle :-When we execute mvn post-clean command, Maven invokes the clean lifecycle consisting of the following phases.
- pre-clean
- clean
- post-clean
Default lifecycle :- This is the primary life cycle of Maven and is used to build the application. It has following 23 phases.
- generate-sources/generate-resources
- compile
- test
- package
- integration-test (pre and post)
- Install
- deploy
Site Lifecycle :- Maven Site plugin is generally used to create fresh documentation to create reports, deploy site etc.
- pre-site
- site
- post-site
- site-deploy
Example Maven Goals :-
mvn install
Invokes generate* and compile, test, package, integration-test, install
mvn clean
Invokes just clean
mvn clean compile
Clean old builds and execute generate*, compile
mvn compile install
Invokes generate*, compile, test, integration-test, package, install
mvn test clean
Invokes generate*, compile, test then cleans
Maven Repositories :-
a repository is a place i.e. directory where all the project jars, library jar, plugins or any other project specific artifacts are stored and can be used by Maven easily.
Dependencies are downloaded from repositories Via http
Maven repository are of three types
- Local :- ${user.home}/.m2/repository
- Central :- http://repo1.maven.org/maven2
- Remote:- nexus repo
Maven Dependency Search Sequence
When we execute Maven build commands, Maven starts looking for dependency libraries in the following sequence:
- Step 1 - Search dependency in local repository, if not found, move to step 2 else if found then do the further processing.
- Step 2 - Search dependency in central repository, if not found and remote repository/repositories is/are mentioned then move to step 4 else if found, then it is downloaded to local repository for future reference.
- Step 3 - If a remote repository has not been mentioned, Maven simply stops the processing and throws error (Unable to find dependency).
- Step 4 - Search dependency in remote repository or repositories, if found then it is downloaded to local repository for future reference otherwise Maven as expected stop processing and throws error (Unable to find dependency).
Defining a repository
- Repositories are defined in the pom
- Repositories can be inherited from parent
<project>
...
<repositories>
<repository>
<id>lds-main</id>
<name>LDS Main
Repo</name>
<url>http://code.lds.org/nexus/content/groups/main-repo</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>


No comments:
Post a Comment