SlideShare une entreprise Scribd logo
1  sur  49
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

Contenu connexe

Tendances (20)

Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Maven
MavenMaven
Maven
 
Core java
Core javaCore java
Core java
 
Testing with Spring: An Introduction
Testing with Spring: An IntroductionTesting with Spring: An Introduction
Testing with Spring: An Introduction
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat Shahriyar
 
Spring Core
Spring CoreSpring Core
Spring Core
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 

En vedette

Xen & the Art of Virtualization
Xen & the Art of VirtualizationXen & the Art of Virtualization
Xen & the Art of VirtualizationTareque Hossain
 
Version Management in Maven
Version Management in MavenVersion Management in Maven
Version Management in MavenGeert Pante
 
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...
Data driven economy: l’impatto sulle infrastrutture IT e la data governance a...IDC Italy
 
virtualization and hypervisors
virtualization and hypervisorsvirtualization and hypervisors
virtualization and hypervisorsGaurav Suri
 
Introduction to Version Control and Configuration Management
Introduction to Version Control and Configuration ManagementIntroduction to Version Control and Configuration Management
Introduction to Version Control and Configuration ManagementPhilip Johnson
 

En vedette (9)

Xen & the Art of Virtualization
Xen & the Art of VirtualizationXen & the Art of Virtualization
Xen & the Art of Virtualization
 
Maven
Maven Maven
Maven
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Version Management in Maven
Version Management in MavenVersion Management in Maven
Version Management in Maven
 
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...
Data driven economy: l’impatto sulle infrastrutture IT e la data governance a...
 
History of java'
History of java'History of java'
History of java'
 
virtualization and hypervisors
virtualization and hypervisorsvirtualization and hypervisors
virtualization and hypervisors
 
Introduction to Version Control and Configuration Management
Introduction to Version Control and Configuration ManagementIntroduction to Version Control and Configuration Management
Introduction to Version Control and Configuration Management
 
Continuous delivery-with-maven
Continuous delivery-with-mavenContinuous delivery-with-maven
Continuous delivery-with-maven
 

Similaire à Maven

Introduction to maven, its configuration, lifecycle and relationship to JS world
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
 
Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management toolRenato Primavera
 
Build Automation using Maven
Build Automation using Maven Build Automation using Maven
Build Automation using Maven Ankit Gubrani
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1MD Sayem Ahmed
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulMert Çalışkan
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by ExampleHsi-Kai Wang
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenMert Çalışkan
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topicGourav Varma
 
(Re)-Introduction to Maven
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to MavenEric Wyles
 
Embrace Maven
Embrace MavenEmbrace Maven
Embrace MavenGuy Marom
 

Similaire à Maven (20)

Maven
MavenMaven
Maven
 
Introduction to maven, its configuration, lifecycle and relationship to JS world
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
 
Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
 
Build Automation using Maven
Build Automation using Maven Build Automation using Maven
Build Automation using Maven
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Maven
MavenMaven
Maven
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
 
Maven
MavenMaven
Maven
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
 
Maven
MavenMaven
Maven
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
 
Maven2交流
Maven2交流Maven2交流
Maven2交流
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
 
Maven basics
Maven basicsMaven basics
Maven basics
 
(Re)-Introduction to Maven
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to Maven
 
Embrace Maven
Embrace MavenEmbrace Maven
Embrace Maven
 
P&MSP2012 - Maven
P&MSP2012 - MavenP&MSP2012 - Maven
P&MSP2012 - Maven
 
Maven
MavenMaven
Maven
 

Dernier

WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 

Dernier (20)

WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 

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>