Maven

Java. Automation Build.
Maven for QC
IT Academy
01/05/2015
Agenda
▪Quick Start
▪Maven Lifecycle
▪Dependency Management
▪Plug-ins
▪IDE Integration
▪SureFire Plug-in
Quick Start
Workflow Build Deploy Test
Don't Applicable to CI Projects
Maven Download
http://maven.apache.org/download.cgi
▪ Maven is a Java tool, so you must have Java installed;
▪ Unzip the distribution archive;
▪ Add the M2_HOME environment variable with the value
C:...Apacheapache-maven-3.2.5
▪ Add to the PATH environment variable with the value
%M2_HOME%bin
Creating Project, Generate POM
mvn archetype:generate
-DgroupId=com.softserve.edu
-DartifactId=work
-Dversion=1.0-SNAPSHOT
-DarchetypeArtifactId=maven-archetype-quickstart
-DarchetypeVersion=1.0
-DinteractiveMode=false
▪ The quickstart archetype is a simple project with JAR
packaging and a single dependency on JUnit. After generating
a project with the quickstart archetype, you will have a single
class.
Single Class
package com.softserve.edu;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[ ] args )
{
System.out.println( "Hello World!" );
}
}
JUnit Test Class
package com.softserve.edu;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class AppTest extends TestCase
{ public AppTest( String testName )
{ super( testName ); }
public static Test suite( )
{ return new TestSuite( AppTest.class ); }
public void testApp( )
{ assertTrue( true ); }
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" … >
<modelVersion>4.0.0</modelVersion>
<groupId>com.softserve.edu</groupId>
<artifactId>work</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>work</name>
<url>http://maven.apache.org</url>
<dependencies> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency> </dependencies>
</project>
New Maven Project
Choose Archetype
Project Structure
Open pom.xml
Maven pom.xml
▪ The POM extends the Super POM;
– Only 4 lines are required.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.softserve.edu</groupId>
<artifactId>assignment</artifactId>
<version>1.0</version>
</project>
Maven Coordinates
▪ A Maven coordinate is a tuple of values that uniquely
identifies any artifact.
▪ Maven coordinates are used throughout Maven configuration
and POM files.
▪ A coordinate comprises three pieces of information:
– The group ID;
– The artifact ID;
– The version.
Maven Coordinates
▪ The group ID:
– The entity or organization responsible for producing the
artifact. For example, com.softserve.edu can be a
group ID.
▪ The artifact ID:
– The name of the actual artifact. For example, a project with
a main class called OpsImp may use OpsImp as its artifact
ID.
▪ The version:
– A version number of the artifact. The supported format is
in the form of mmm.nnn.bbb-qqqqqqq-dd, where mmm is
the major version number, nnn is the minor version
number, and bbb is the bugfix level. Optionally, either
qqqqq (qualifier) or dd (build number) can also be added
to the version number.
Maven pom.xml
Maven Directories Structure
Maven Directories Structure
▪ src/main/java Java source files goes here;
▪ src/main/resources Other resources your application needs;
▪ src/main/filters Resource filters (properties files);
▪ src/main/config Configuration files;
▪ src/main/webapp Web application directory for a WAR
project;
▪ src/test/java Test sources like unit tests (not deployed);
▪ src/test/resources Test resources (not deployed);
▪ src/test/filters Test resource filter files (not deployed);
▪ src/site Files used to generate the Maven project website;
▪ target/ The target directory is used to house all output of the
build.
Maven Lifecycle
Maven Lifecycle and Phases
▪ The build lifecycle is the process of building and distributing
an artifact.
▪ A phase is a step in the build lifecycle.
▪ Most important default phases:
– Validate
– Compile
– Test
– Package
– Install
– Deploy
▪ Some common phases not default:
– Clean
– Site
Maven Lifecycle and Phases
▪ Package – Take the compiled code and package it in its
distributable format (JAR, WAR, etc.);
▪ pre-integration-test – Perform actions required before
integration tests are executed;
▪ integration-test – Process and deploy the package if
necessary into an environment where integration tests can be
run;
▪ post-integration-test – Perform actions required after
integration tests have been executed;
▪ verify – Run any checks to verify the package is valid and
meets quality criteria;
▪ install – Install the package into the local repository;
▪ deploy – Copies the final package to the remote repository.
Maven Commands
▪ Validate the project is correct and all necessary information is
available
mvn validate
▪ Compile the source code of the project
mvn compile
▪ Run unit tests from Command line
mvn test
▪ Take the compiled code and package it in its distributable
format, such as a JAR
mvn package
▪ Run integration tests from Command line
mvn verify
Dependency Management
Dependency Management
▪ JUnit is the de facto standard unit testing library for the Java
language.
▪ Dependencies are defined in the POM.
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
Dependency Management
▪ Repository: A shared location for dependencies which all
projects can access
– Only one exists;
– Stored outside the project.
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>
</dependencies>
Dependency Scope. Examples
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
▪ Code dependent on the API. Implementation can be changed.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
<scope>runtime</scope>
</dependency>
Repositories
▪ Local repository:
– Copy on local computer which
is a cache of the remote
downloads;
– May contain project-local build
artifacts as well;
– Located in (by default)
USER_HOME/.m2/repository
Update pom.xml for Selenium
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
</dependencies>
Plug-ins
Maven Operation Model
▪ Maven is based on the Plugin-architecture, which allows the
use of plug-ins for various tasks: compile, test, build, deploy,
checkstyle, etc.
Maven Plugins
▪ clean Clean up target after the build. Deletes the target
directory.
▪ compiler Compiles Java source files.
▪ surefile Run the JUnit unit tests. Creates test reports.
▪ failsafe Run integration tests while the Surefire Plugins is
designed to run unit tests.
▪ jar Builds a JAR file from the current project.
▪ war Builds a WAR file from the current project.
▪ javadoc Generates Javadoc for the project.
▪ antrun Runs a set of ant tasks from any phase mentioned of
the build.
Plug-ins Execution
mvn [plugin-name]:[goal-name]
▪ The following lifecycle bindings
Phase Plugin execution goal
test surefire:test
integration-test failsafe:integration-test
verify failsafe:verify
Maven Plugins
▪ Maven is – at its heart – a plugin execution framework.
– All work is done by plugins. Looking for a specific goal to
execute.
▪ There are the build and the reporting plugins:
– Build plugins will be executed during the build and they
should be configured in the <build/> element from the
POM.
– Reporting plugins will be executed during the site
generation and they should be configured in
the <reporting/> element from the POM.
Maven Compiler Plugin
▪ Compiler – the main plugin. It is used in almost all projects.
Available by default, but in almost every project it has to re-
declare. The default settings are not very suitable.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
IDE Integration
Eclipse. Import Project
Configure Build Path
Repositories. Update Index
Eclipse Kepler. Configure Maven
Eclipse Kepler. Add Dependencies
Selenium WebDriver
▪ Run tests from Eclipse
SureFire Plug-in
Surefire Plugin
▪ Surefire Plugin will automatically include all test classes:
– "**/Test*.java" includes all of its subdirectories and all
java filenames that start with "Test“;
– "**/*Test.java" includes all of its subdirectories and
all java filenames that end with "Test“;
– "**/*TestCase.java" includes all of its subdirectories
and all java filenames that end with "TestCase".
Surefire Plugin. Include Test
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<includes>
<include>**/SearchTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
Inclusions and Exclusions
▪ Inclusions Tests
<configuration>
<includes>
<include>Sample.java</include>
</includes>
</configuration>
▪ Exclusions Tests
<configuration>
<excludes>
<exclude>**/TestCircle.java</exclude>
</excludes>
</configuration>
Using TestNG
▪ Using TestNG suite XML files allows flexible configuration of
the tests to be run. These files are created in the normal way,
and then added to the Surefire Plugin configuration
<build> <plugins> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin> </plugins> </build>
Maven
1 de 49

Recomendados

Maven Basics - Explained por
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - ExplainedSmita Prasad
1.1K visualizações46 slides
Maven tutorial por
Maven tutorialMaven tutorial
Maven tutorialDragos Balan
1.8K visualizações52 slides
Maven por
MavenMaven
MavenVineela Madarapu
979 visualizações19 slides
An Introduction to Maven por
An Introduction to MavenAn Introduction to Maven
An Introduction to MavenVadym Lotar
13.9K visualizações40 slides
Maven ppt por
Maven pptMaven ppt
Maven pptnatashasweety7
4.6K visualizações21 slides
Maven Introduction por
Maven IntroductionMaven Introduction
Maven IntroductionSandeep Chawla
21.1K visualizações31 slides

Mais conteúdo relacionado

Mais procurados

Spring boot por
Spring bootSpring boot
Spring bootGyanendra Yadav
1.9K visualizações32 slides
Apache Maven por
Apache MavenApache Maven
Apache MavenRahul Tanwani
2.1K visualizações35 slides
Maven Overview por
Maven OverviewMaven Overview
Maven OverviewFastConnect
8.5K visualizações29 slides
Tomcat Server por
Tomcat ServerTomcat Server
Tomcat ServerAnirban Majumdar
11.1K visualizações19 slides
Introduction to java (revised) por
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)Sujit Majety
730 visualizações75 slides
Tomcat and apache httpd training por
Tomcat and apache httpd trainingTomcat and apache httpd training
Tomcat and apache httpd trainingFranck SIMON
28K visualizações278 slides

Mais procurados(20)

Spring boot por Gyanendra Yadav
Spring bootSpring boot
Spring boot
Gyanendra Yadav1.9K visualizações
Apache Maven por Rahul Tanwani
Apache MavenApache Maven
Apache Maven
Rahul Tanwani2.1K visualizações
Maven Overview por FastConnect
Maven OverviewMaven Overview
Maven Overview
FastConnect8.5K visualizações
Tomcat Server por Anirban Majumdar
Tomcat ServerTomcat Server
Tomcat Server
Anirban Majumdar11.1K visualizações
Introduction to java (revised) por Sujit Majety
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
Sujit Majety730 visualizações
Tomcat and apache httpd training por Franck SIMON
Tomcat and apache httpd trainingTomcat and apache httpd training
Tomcat and apache httpd training
Franck SIMON28K visualizações
Selenium por Batch2016
SeleniumSelenium
Selenium
Batch2016438 visualizações
PUC SE Day 2019 - SpringBoot por Josué Neis
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
Josué Neis696 visualizações
Maven 3 Overview por Mike Ensor
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
Mike Ensor2.7K visualizações
Spring boot por sdeeg
Spring bootSpring boot
Spring boot
sdeeg26.6K visualizações
Tomcat server por Utkarsh Agarwal
 Tomcat server Tomcat server
Tomcat server
Utkarsh Agarwal2.7K visualizações
Introduction to Java por Professional Guru
Introduction to JavaIntroduction to Java
Introduction to Java
Professional Guru1.6K visualizações
Introduction to java por Sandeep Rawat
Introduction to java Introduction to java
Introduction to java
Sandeep Rawat1.4K visualizações
Selenium ppt por Naga Dinesh
Selenium pptSelenium ppt
Selenium ppt
Naga Dinesh506 visualizações
Spring Framework - MVC por Dzmitry Naskou
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVC
Dzmitry Naskou10.7K visualizações
Introduction to Spring Framework por Serhat Can
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can26K visualizações
Test Automation and Selenium por Karapet Sarkisyan
Test Automation and SeleniumTest Automation and Selenium
Test Automation and Selenium
Karapet Sarkisyan2.4K visualizações
WebLogic Scripting Tool Overview por James Bayer
WebLogic Scripting Tool OverviewWebLogic Scripting Tool Overview
WebLogic Scripting Tool Overview
James Bayer22.7K visualizações
Maven por Jyothi Malapati
MavenMaven
Maven
Jyothi Malapati1.7K visualizações

Destaque

Xen & the Art of Virtualization por
Xen & the Art of VirtualizationXen & the Art of Virtualization
Xen & the Art of VirtualizationTareque Hossain
4.2K visualizações17 slides
Maven por
Maven Maven
Maven Khan625
905 visualizações9 slides
Introduction to Maven por
Introduction to MavenIntroduction to Maven
Introduction to MavenOnkar Deshpande
3.4K visualizações67 slides
Version Management in Maven por
Version Management in MavenVersion Management in Maven
Version Management in MavenGeert Pante
11.9K visualizações26 slides
Data driven economy: l’impatto sulle infrastrutture IT e la data governance a... por
Data driven economy: l’impatto sulle infrastrutture IT e la data governance a...Data driven economy: l’impatto sulle infrastrutture IT e la data governance a...
Data driven economy: l’impatto sulle infrastrutture IT e la data governance a...IDC Italy
1.3K visualizações9 slides
History of java' por
History of java'History of java'
History of java'deepthisujithra
14.6K visualizações35 slides

Destaque(9)

Xen & the Art of Virtualization por Tareque Hossain
Xen & the Art of VirtualizationXen & the Art of Virtualization
Xen & the Art of Virtualization
Tareque Hossain4.2K visualizações
Maven por Khan625
Maven Maven
Maven
Khan625905 visualizações
Introduction to Maven por Onkar Deshpande
Introduction to MavenIntroduction to Maven
Introduction to Maven
Onkar Deshpande3.4K visualizações
Version Management in Maven por Geert Pante
Version Management in MavenVersion Management in Maven
Version Management in Maven
Geert Pante11.9K visualizações
Data driven economy: l’impatto sulle infrastrutture IT e la data governance a... por IDC Italy
Data driven economy: l’impatto sulle infrastrutture IT e la data governance a...Data driven economy: l’impatto sulle infrastrutture IT e la data governance a...
Data driven economy: l’impatto sulle infrastrutture IT e la data governance a...
IDC Italy 1.3K visualizações
History of java' por deepthisujithra
History of java'History of java'
History of java'
deepthisujithra14.6K visualizações
virtualization and hypervisors por Gaurav Suri
virtualization and hypervisorsvirtualization and hypervisors
virtualization and hypervisors
Gaurav Suri42.3K visualizações
Introduction to Version Control and Configuration Management por Philip Johnson
Introduction to Version Control and Configuration ManagementIntroduction to Version Control and Configuration Management
Introduction to Version Control and Configuration Management
Philip Johnson8.7K visualizações

Similar a Maven

Maven por
MavenMaven
MavenShraddha
416 visualizações24 slides
Introduction to maven, its configuration, lifecycle and relationship to JS world por
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldDmitry Bakaleinik
691 visualizações91 slides
Apache maven, a software project management tool por
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management toolRenato Primavera
1.6K visualizações57 slides
Build Automation using Maven por
Build Automation using Maven Build Automation using Maven
Build Automation using Maven Ankit Gubrani
3.7K visualizações45 slides
maven-cheat-sheet.pdf por
maven-cheat-sheet.pdfmaven-cheat-sheet.pdf
maven-cheat-sheet.pdfssuser8ff3dc
70 visualizações1 slide
An Introduction to Maven Part 1 por
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1MD Sayem Ahmed
899 visualizações23 slides

Similar a Maven(20)

Maven por Shraddha
MavenMaven
Maven
Shraddha416 visualizações
Introduction to maven, its configuration, lifecycle and relationship to JS world por Dmitry Bakaleinik
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS world
Dmitry Bakaleinik691 visualizações
Apache maven, a software project management tool por Renato Primavera
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
Renato Primavera1.6K visualizações
Build Automation using Maven por Ankit Gubrani
Build Automation using Maven Build Automation using Maven
Build Automation using Maven
Ankit Gubrani3.7K visualizações
maven-cheat-sheet.pdf por ssuser8ff3dc
maven-cheat-sheet.pdfmaven-cheat-sheet.pdf
maven-cheat-sheet.pdf
ssuser8ff3dc70 visualizações
An Introduction to Maven Part 1 por MD Sayem Ahmed
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
MD Sayem Ahmed899 visualizações
Intelligent Projects with Maven - DevFest Istanbul por Mert Çalışkan
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
Mert Çalışkan1.3K visualizações
Maven por Fabio Bonfante
MavenMaven
Maven
Fabio Bonfante829 visualizações
Learning Maven by Example por Hsi-Kai Wang
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
Hsi-Kai Wang1.6K visualizações
Maven por feng lee
MavenMaven
Maven
feng lee1.8K visualizações
BMO - Intelligent Projects with Maven por Mert Çalışkan
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
Mert Çalışkan1.6K visualizações
Maven por Nishant Arora
MavenMaven
Maven
Nishant Arora98 visualizações
Jenkins advance topic por Gourav Varma
Jenkins advance topicJenkins advance topic
Jenkins advance topic
Gourav Varma182 visualizações
Maven2交流 por ChangQi Lin
Maven2交流Maven2交流
Maven2交流
ChangQi Lin331 visualizações
Mavennotes.pdf por AnkurSingh656748
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
AnkurSingh6567489 visualizações
(Re)-Introduction to Maven por Eric Wyles
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to Maven
Eric Wyles127 visualizações
Embrace Maven por Guy Marom
Embrace MavenEmbrace Maven
Embrace Maven
Guy Marom213 visualizações
P&MSP2012 - Maven por Daniele Dell'Aglio
P&MSP2012 - MavenP&MSP2012 - Maven
P&MSP2012 - Maven
Daniele Dell'Aglio484 visualizações
Maven por Jyothi Malapati
MavenMaven
Maven
Jyothi Malapati514 visualizações

Último

DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon por
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - AfternoonDSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - AfternoonDeltares
13 visualizações43 slides
DevsRank por
DevsRankDevsRank
DevsRankdevsrank786
11 visualizações1 slide
Neo4j y GenAI por
Neo4j y GenAI Neo4j y GenAI
Neo4j y GenAI Neo4j
42 visualizações41 slides
What Can Employee Monitoring Software Do?​ por
What Can Employee Monitoring Software Do?​What Can Employee Monitoring Software Do?​
What Can Employee Monitoring Software Do?​wAnywhere
21 visualizações11 slides
Citi TechTalk Session 2: Kafka Deep Dive por
Citi TechTalk Session 2: Kafka Deep DiveCiti TechTalk Session 2: Kafka Deep Dive
Citi TechTalk Session 2: Kafka Deep Diveconfluent
17 visualizações60 slides
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... por
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...Deltares
6 visualizações15 slides

Último(20)

DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon por Deltares
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - AfternoonDSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
Deltares13 visualizações
DevsRank por devsrank786
DevsRankDevsRank
DevsRank
devsrank78611 visualizações
Neo4j y GenAI por Neo4j
Neo4j y GenAI Neo4j y GenAI
Neo4j y GenAI
Neo4j42 visualizações
What Can Employee Monitoring Software Do?​ por wAnywhere
What Can Employee Monitoring Software Do?​What Can Employee Monitoring Software Do?​
What Can Employee Monitoring Software Do?​
wAnywhere21 visualizações
Citi TechTalk Session 2: Kafka Deep Dive por confluent
Citi TechTalk Session 2: Kafka Deep DiveCiti TechTalk Session 2: Kafka Deep Dive
Citi TechTalk Session 2: Kafka Deep Dive
confluent17 visualizações
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... por Deltares
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
Deltares6 visualizações
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the... por Deltares
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
Deltares6 visualizações
Fleet Management Software in India por Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 visualizações
Unleash The Monkeys por Jacob Duijzer
Unleash The MonkeysUnleash The Monkeys
Unleash The Monkeys
Jacob Duijzer7 visualizações
Navigating container technology for enhanced security by Niklas Saari por Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy8 visualizações
SUGCON ANZ Presentation V2.1 Final.pptx por Jack Spektor
SUGCON ANZ Presentation V2.1 Final.pptxSUGCON ANZ Presentation V2.1 Final.pptx
SUGCON ANZ Presentation V2.1 Final.pptx
Jack Spektor22 visualizações
SAP FOR CONTRACT MANUFACTURING.pdf por Virendra Rai, PMP
SAP FOR CONTRACT MANUFACTURING.pdfSAP FOR CONTRACT MANUFACTURING.pdf
SAP FOR CONTRACT MANUFACTURING.pdf
Virendra Rai, PMP11 visualizações
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit... por Deltares
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
Deltares13 visualizações
El Arte de lo Possible por Neo4j
El Arte de lo PossibleEl Arte de lo Possible
El Arte de lo Possible
Neo4j38 visualizações
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs por Deltares
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
Deltares7 visualizações
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx por animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm13 visualizações
Tridens DevOps por Tridens
Tridens DevOpsTridens DevOps
Tridens DevOps
Tridens9 visualizações
Cycleops - Automate deployments on top of bare metal.pptx por Thanassis Parathyras
Cycleops - Automate deployments on top of bare metal.pptxCycleops - Automate deployments on top of bare metal.pptx
Cycleops - Automate deployments on top of bare metal.pptx
Thanassis Parathyras30 visualizações
Software testing company in India.pptx por SakshiPatel82
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptx
SakshiPatel827 visualizações

Maven

  • 1. Java. Automation Build. Maven for QC IT Academy 01/05/2015
  • 2. Agenda ▪Quick Start ▪Maven Lifecycle ▪Dependency Management ▪Plug-ins ▪IDE Integration ▪SureFire Plug-in
  • 5. Don't Applicable to CI Projects
  • 6. Maven Download http://maven.apache.org/download.cgi ▪ Maven is a Java tool, so you must have Java installed; ▪ Unzip the distribution archive; ▪ Add the M2_HOME environment variable with the value C:...Apacheapache-maven-3.2.5 ▪ Add to the PATH environment variable with the value %M2_HOME%bin
  • 7. Creating Project, Generate POM mvn archetype:generate -DgroupId=com.softserve.edu -DartifactId=work -Dversion=1.0-SNAPSHOT -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.0 -DinteractiveMode=false ▪ The quickstart archetype is a simple project with JAR packaging and a single dependency on JUnit. After generating a project with the quickstart archetype, you will have a single class.
  • 8. Single Class package com.softserve.edu; /** * Hello world! * */ public class App { public static void main( String[ ] args ) { System.out.println( "Hello World!" ); } }
  • 9. JUnit Test Class package com.softserve.edu; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; public class AppTest extends TestCase { public AppTest( String testName ) { super( testName ); } public static Test suite( ) { return new TestSuite( AppTest.class ); } public void testApp( ) { assertTrue( true ); } }
  • 10. pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" … > <modelVersion>4.0.0</modelVersion> <groupId>com.softserve.edu</groupId> <artifactId>work</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>work</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
  • 15. Maven pom.xml ▪ The POM extends the Super POM; – Only 4 lines are required. <project> <modelVersion>4.0.0</modelVersion> <groupId>com.softserve.edu</groupId> <artifactId>assignment</artifactId> <version>1.0</version> </project>
  • 16. Maven Coordinates ▪ A Maven coordinate is a tuple of values that uniquely identifies any artifact. ▪ Maven coordinates are used throughout Maven configuration and POM files. ▪ A coordinate comprises three pieces of information: – The group ID; – The artifact ID; – The version.
  • 17. Maven Coordinates ▪ The group ID: – The entity or organization responsible for producing the artifact. For example, com.softserve.edu can be a group ID. ▪ The artifact ID: – The name of the actual artifact. For example, a project with a main class called OpsImp may use OpsImp as its artifact ID. ▪ The version: – A version number of the artifact. The supported format is in the form of mmm.nnn.bbb-qqqqqqq-dd, where mmm is the major version number, nnn is the minor version number, and bbb is the bugfix level. Optionally, either qqqqq (qualifier) or dd (build number) can also be added to the version number.
  • 20. Maven Directories Structure ▪ src/main/java Java source files goes here; ▪ src/main/resources Other resources your application needs; ▪ src/main/filters Resource filters (properties files); ▪ src/main/config Configuration files; ▪ src/main/webapp Web application directory for a WAR project; ▪ src/test/java Test sources like unit tests (not deployed); ▪ src/test/resources Test resources (not deployed); ▪ src/test/filters Test resource filter files (not deployed); ▪ src/site Files used to generate the Maven project website; ▪ target/ The target directory is used to house all output of the build.
  • 22. Maven Lifecycle and Phases ▪ The build lifecycle is the process of building and distributing an artifact. ▪ A phase is a step in the build lifecycle. ▪ Most important default phases: – Validate – Compile – Test – Package – Install – Deploy ▪ Some common phases not default: – Clean – Site
  • 23. Maven Lifecycle and Phases ▪ Package – Take the compiled code and package it in its distributable format (JAR, WAR, etc.); ▪ pre-integration-test – Perform actions required before integration tests are executed; ▪ integration-test – Process and deploy the package if necessary into an environment where integration tests can be run; ▪ post-integration-test – Perform actions required after integration tests have been executed; ▪ verify – Run any checks to verify the package is valid and meets quality criteria; ▪ install – Install the package into the local repository; ▪ deploy – Copies the final package to the remote repository.
  • 24. Maven Commands ▪ Validate the project is correct and all necessary information is available mvn validate ▪ Compile the source code of the project mvn compile ▪ Run unit tests from Command line mvn test ▪ Take the compiled code and package it in its distributable format, such as a JAR mvn package ▪ Run integration tests from Command line mvn verify
  • 26. Dependency Management ▪ JUnit is the de facto standard unit testing library for the Java language. ▪ Dependencies are defined in the POM. <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies>
  • 27. Dependency Management ▪ Repository: A shared location for dependencies which all projects can access – Only one exists; – Stored outside the project. <dependencies> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8.8</version> <scope>test</scope> </dependency> </dependencies>
  • 28. Dependency Scope. Examples <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.5</version> </dependency> ▪ Code dependent on the API. Implementation can be changed. <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.5</version> <scope>runtime</scope> </dependency>
  • 29. Repositories ▪ Local repository: – Copy on local computer which is a cache of the remote downloads; – May contain project-local build artifacts as well; – Located in (by default) USER_HOME/.m2/repository
  • 30. Update pom.xml for Selenium <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-server</artifactId> <version>2.44.0</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.44.0</version> </dependency> </dependencies>
  • 32. Maven Operation Model ▪ Maven is based on the Plugin-architecture, which allows the use of plug-ins for various tasks: compile, test, build, deploy, checkstyle, etc.
  • 33. Maven Plugins ▪ clean Clean up target after the build. Deletes the target directory. ▪ compiler Compiles Java source files. ▪ surefile Run the JUnit unit tests. Creates test reports. ▪ failsafe Run integration tests while the Surefire Plugins is designed to run unit tests. ▪ jar Builds a JAR file from the current project. ▪ war Builds a WAR file from the current project. ▪ javadoc Generates Javadoc for the project. ▪ antrun Runs a set of ant tasks from any phase mentioned of the build.
  • 34. Plug-ins Execution mvn [plugin-name]:[goal-name] ▪ The following lifecycle bindings Phase Plugin execution goal test surefire:test integration-test failsafe:integration-test verify failsafe:verify
  • 35. Maven Plugins ▪ Maven is – at its heart – a plugin execution framework. – All work is done by plugins. Looking for a specific goal to execute. ▪ There are the build and the reporting plugins: – Build plugins will be executed during the build and they should be configured in the <build/> element from the POM. – Reporting plugins will be executed during the site generation and they should be configured in the <reporting/> element from the POM.
  • 36. Maven Compiler Plugin ▪ Compiler – the main plugin. It is used in almost all projects. Available by default, but in almost every project it has to re- declare. The default settings are not very suitable. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin>
  • 42. Eclipse Kepler. Add Dependencies
  • 43. Selenium WebDriver ▪ Run tests from Eclipse
  • 45. Surefire Plugin ▪ Surefire Plugin will automatically include all test classes: – "**/Test*.java" includes all of its subdirectories and all java filenames that start with "Test“; – "**/*Test.java" includes all of its subdirectories and all java filenames that end with "Test“; – "**/*TestCase.java" includes all of its subdirectories and all java filenames that end with "TestCase".
  • 46. Surefire Plugin. Include Test <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.16</version> <configuration> <includes> <include>**/SearchTest.java</include> </includes> </configuration> </plugin> </plugins> </build>
  • 47. Inclusions and Exclusions ▪ Inclusions Tests <configuration> <includes> <include>Sample.java</include> </includes> </configuration> ▪ Exclusions Tests <configuration> <excludes> <exclude>**/TestCircle.java</exclude> </excludes> </configuration>
  • 48. Using TestNG ▪ Using TestNG suite XML files allows flexible configuration of the tests to be run. These files are created in the normal way, and then added to the Surefire Plugin configuration <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.17</version> <configuration> <suiteXmlFiles> <suiteXmlFile>testng.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin> </plugins> </build>