Topics covered. Introduction to Maven Maven for Dependency Management Maven Lifecycles and Plugins Hands on session. Maven 2

Similar documents
Content. Development Tools 2(57)

Maven POM project modelversion groupid artifactid packaging version name

MAVEN INTERVIEW QUESTIONS

Maven. INF5750/ Lecture 2 (Part II)

MAVEN MOCK TEST MAVEN MOCK TEST I

What is Maven? Apache Maven is a software project management and comprehension tool (build, test, packaging, reporting, site, deploy).

I Got My Mojo Workin'

MAVEN MOCK TEST MAVEN MOCK TEST IV

MAVEN MOCK TEST MAVEN MOCK TEST III

Setting up a Maven Project

AUTOMATION TESTING FRAMEWORK FOR LUMINOUS LMS

Simplified Build Management with Maven

Repository Management and Sonatype Nexus. Repository Management and Sonatype Nexus

Sonatype CLM - IDE User Guide. Sonatype CLM - IDE User Guide

juddi Developer Guide

Hello Maven. TestNG, Eclipse, IntelliJ IDEA. Óbuda University, Java Enterprise Edition John von Neumann Faculty of Informatics Lab 2.

DevOps and Maven. Eamonn de Leastar Dr. Siobhán Drohan Produced by:

Pour aller plus loin : Programmation outillée

Component based Development. Table of Contents. Notes. Notes. Notes. Web Application Development. Zsolt Tóth

sites</distribsiteroot>

JPA Tools Guide (v5.0)

Cheat Sheet: Wildfly Swarm

Maven Introduction to Concepts: POM, Dependencies, Plugins, Phases

Continuous Integration INRIA

JDO Tools Guide (v5.1)

Maven 2 & Continuum. by Trygve Laugstøl

Moven. Machine/Deep Learning Models Distribution Relying on the Maven Infrastructure. Sergio Fernández (Redlink GmbH) November 14th, Sevilla

Apache Maven. Created by anova r&d bvba

TOP REASONS WHY YOU SHOULD SWITCH TO MAVEN 3

Oracle Code Day Hands On Labs (HOL) (Install, Repository, Local Deploy, DevCS, OACCS)

Red Hat Fuse 7.0 Deploying into Apache Karaf

Fat / Uber jars - Using the Shade Plugin

Packaging, automation, Continuous Integration

Sonatype CLM Enforcement Points - Nexus. Sonatype CLM Enforcement Points - Nexus

Red Hat Fuse 7.0 Installing on Apache Karaf

Continuous Integration with Jenkins

maven Build System Making Projects Make Sense

Apache Maven MarsJUG. Arnaud Héritier exo platform Software Factory Manager

Unable To The Artifact From Any Repository Maven-clean-plugin

This tutorial explains how you can use Gradle as a build automation tool for Java as well as Groovy projects.

Selenium Testing Course Content

Package Management and Build Tools

HP Operations Orchestration

Set up Maven plugins in Eclipse. Creating a new project

Jaxb2 Maven Plugin Could Not Process Schema

BUILD AND DEPLOY SOA PROJECTS FROM DEVELOPER CLOUD SERVICE TO ORACLE SOA CLOUD SERVICE

Red Hat Decision Manager 7.1 Packaging and deploying a Red Hat Decision Manager project

Gant as Ant and Maven Replacement

HP Operations Orchestration

vrealize Code Stream Plug-In SDK Development Guide

Oracle Code Day Hands On Labs HOL

What s NetBeans? Like Eclipse:

Tuscany: Applying OSGi modularity after the fact

Administering Apache Geronimo With Custom Server Assemblies and Maven. David Jencks

Struts 2 Maven Archetypes

Build Tools. Software Engineering SS A tool was needed. Agenda for today. Build tools. Software complexity. Build tools

4. Check the site specified in previous step to work with, expand Maven osgi-bundles, and select slf4j.api,

MANUAL DO ALUNO DE ENGENHARIA DE SOFTWARE

Build Tools. Software Engineering SS 2007

Introducere in Maven. Information Type: Working Standard, Disclosure Range:, Information Owner: mihai.hulea, NTT DATA Romania

Contents. Enterprise Systems Maven and Log4j. Maven. What is maven?

Maven Plugin Guide OpenL Tablets BRMS Release 5.16

JavaLand Dirk Mahler

Maven in the wild. An introduction to Maven

An Integrated Approach to Managing Windchill Customizations. Todd Baltes Lead PLM Technical Architect SRAM

EPL451: Data Mining on the Web Lab 6

Red Hat JBoss Fuse 6.3

STQA Mini Project No. 1

MIGRATION GUIDE DIGITAL EXPERIENCE MANAGER 7.2

Red Hat JBoss Migration Toolkit 2.7 Windup User Guide

TIBCO StreamBase 10.2 Building and Running Applications in Studio, Studio Projects and Project Structure. November 2017

Class Dependency Analyzer CDA Developer Guide

Action Developers Guide

Build Automation Kurt Christensen

Produced by. Agile Software Development. Eamonn de Leastar

Software Engineering 2 A practical course in software engineering. Ekkart Kindler

... Apache Maven PDF Plugin v. 1.4 User Guide.... The Apache Software Foundation

Developing ONOS Apps

Session 24. Spring Framework Introduction. Reading & Reference. dev.to/lechatthecat/how-to-use-spring-boot-java-web-framework-withintellij-idea-202p

What s new in IBM Operational Decision Manager 8.9 Standard Edition

JUG Saxony Day Dirk Mahler

JPA Enhancement Guide (v5.1)

Red Hat JBoss Enterprise Application Platform 6.4

Usage and Customization Guide. OpenL Tablets Rule Service Release 5.18

Red Hat JBoss Fuse 6.1

Introduction to project industrialization using Maven YaJUG 06/10/2009. Copyright Pierre-Antoine Grégoire License Creative Commons 2.

Getting started with Geomajas. Geomajas Developers and Geosparc

Usage and Customization Guide. OpenL Tablets Rule Service Release 5.19

Red Hat JBoss Migration Toolkit 3.0 Windup User Guide

Android Sdk Install Documentation Eclipse. Ubuntu >>>CLICK HERE<<<

Red Hat Application Migration Toolkit 4.2

Red Hat JBoss Fuse 6.1

Tattletale. What is Tattletale? Enterprise archives JBoss Application Server 7 Putting it all together Roadmap

Demystifying OSGi bundles Excerpted from

Apache Maven: Best Practices

Sample Spark Web-App. Overview. Prerequisites

IoTivity Programmer s Guide Resource Encapsulation

Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p.

Overall Design of SSS Software

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

Transcription:

Maven Maven 1

Topics covered Introduction to Maven Maven for Dependency Management Maven Lifecycles and Plugins Hands on session Maven 2

Introduction to Maven Maven 3

What is Maven? A Java project management and integration build tool. Based on the concept of XML Project Object Model (POM). Maven can manage a project's build, testing, reporting, documentation and releases from a central piece of information Licensed by Apache Stores libraries and plugins in a central repository Maven 4

Maven s Objectives Making the build process easy Providing a uniform build system Providing quality project information Maven provides plenty of useful project information that is in part taken from your POM and in part generated from your project s sources Providing guidelines for best practices development Maven aims to gather current principles for best practices development, and make it easy to guide a project in that direction. For example, specification, execution, and reporting of unit tests are part of the normal build cycle using Maven. Allowing transparent migration to new features Maven provides an easy way for the installation of new or updated plugins Maven 5

How does it work? Build controlled via pom.xml project file POM = Project Object Model Uses standard build order, directories, plugins Identifies dependencies in the pom.xml Maven 6

Maven for Dependency Management Maven 7

Maven repositories In Maven terminology, a repository is a directory where all the project jars, library jar, plugins or any other project specific artifacts are stored and can be used by Maven easily. Maven repository are of three types: local, Maven local repository is a folder location on your machine. It gets created when you run any maven command for the first time. central, Maven central repository is repository provided by Maven community: https://search.maven.org/ remote, developer's own custom repository containing required libraries or other project jars Remote repository are defined within tag <repositories> Maven 8

Handling Dependencies with Maven Unless your project is small, your project may need external Java APIs or frameworks which are usually packaged in their own JAR or WAR files. These JAR files are needed on the classpath when you compile your project code. Dependency management is one of the features of Maven that is best known. In the POM file you specify what external libraries your project depends on, and which version, and then Maven downloads them for you and puts them in your local Maven repository. These external libraries are called dependencies. Maven 9

Transitive dependencies If any of these external libraries need other libraries, then these other libraries are also downloaded into your local Maven repository. This feature allows you to avoid needing to discover and specify the dependencies that your own dependencies require, and including them automatically. E.g. If my project depends on A and A depends on B. I don t have to specify B in my POM file Nearest definition. The version used will be the closest one to your project in the tree of dependencies. e.g. if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0 Maven 10

Scope of a Dependency Dependency scope is used to limit the transitivity of a dependency, and also to affect the classpath used for various build tasks. There are 6 scopes available: compile, default scope. Compile dependencies are available in all classpaths of a project. Those dependencies are propagated to dependent projects. provided, similar to compile, but indicates you expect the JDK or a container to provide the dependency at runtime. This scope is only available on the compilation and test classpath, and is not transitive. In other words, it means that the JAR is added in the classpath by Maven during compilation, but at run time there is already a JAR provided by the environment. runtime, indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath. test, indicates that the dependency is required only for the test compilation and execution phases. This scope is not transitive. system import Maven 11

Adding a Dependency The dependency must be enclosed by the element <dependency> and added into the element <dependencies> We must provide groupid artifactid version type (default jar) scope (default compile) Maven 12

Adding a Dependency - Example E.g. <project>... <dependencies> <dependency> <groupid>group-c</groupid> <artifactid>artifact-b</artifactid> <version>1.0</version> <type>war</type> <scope>runtime</scope> </dependency> </project> We are adding the dependency group-c:artifact-b:1.0 with scope runtime and the dependency is packaged as war. Maven 13

Maven dependency mechanism (How Maven finds the dependencies) 1. Search the dependency in Maven local repository (~/.m2/ in Linux) 2. Search the dependency in Maven central repository (https://search.maven.org) 3. Search the dependency among Maven remote repositories (if defined in pom.xml) Maven 14

Maven dependency mechanism (https://search.maven.org/) Maven 15

Maven dependency mechanism - Example Aim: we need the log4j library We need to know the log4j Maven coordinates, for example <groupid>log4j</groupid> <artifactid>log4j</artifactid> <version>1.2.14</version> We declare the log4j Maven coordinates into pom.xml file. We enclose the coordinates within the <dependency> element and in turn within the <dependencies> element When Maven is compiling or building, the log4j jar will be downloaded automatically and put it into your Maven local repository (if not already in the local repository) All managed by Maven The Maven coordinates can be found by visiting the Maven Central Repository Maven 16

Maven Lifecycles and Plugins Maven 17

Maven Build Lifecycles Maven is based around the central concept of a build lifecycle. The process for building and distributing a particular artifact (project) is clearly defined. The POM file contains all the information for the build lifecycle The user have to learn a small set of commands There are three built-in lifecycles: clean, handles project cleaning default, handles the project building, testing and deployment site, handles the creation of project's site documentation. A Maven build lifecycle is defined by a list of build phases a build phase represents a stage in the lifecycle The lifecycle phases are executed sequentially Maven 18

Clean Lifecycle pre-clean, execute processes needed prior to the actual project cleaning clean, remove all files generated by the previous build post-clean, execute processes needed to finalize the project cleaning Maven 19

Default Lifecycle The defaule lifecycle has validate, validate the project is correct and all necessary information is available compile, compile the source code of the project test, test the compiled source code using a suitable unit testing framework. package, take the compiled code and package it in its distributable format, such as a JAR. verify, run integration tests install, install the package into the local repository, for use as a dependency in other projects locally deploy, copies the final package to the remote repository for sharing with other developers and projects. Maven 20

Site Lifecycle pre-site, execute processes needed prior to the actual project site generation site, generate the project's site documentation post-site, execute processes needed to finalize the site generation, and to prepare for site deployment site-deploy, deploy the generated site documentation to the specified web server Maven 21

Maven main commands To execute a phase on Maven you can use the command mvn mvn <phase_name> It executes all the previous phases in a lifecycle, before executing the one specified Example: mvn install This command executes each default life cycle phase in order (validate, compile, test, package, verify), before executing install Maven 22

Maven Plugins Maven is - at its heart - a plugin execution framework; all work is done by plugins. Plugins are artifacts that provide goals to Maven. A plugin may have one or more goals. Each goal represents a capability of that plugin. There are two types of 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 23

Maven Goals A goal is a unit of work in Maven. It is possible to execute goals independently or a part of a larger chain of goals. A goal can be executed independently using the following syntax: mvn [plugin-name]:[goal-name] You can add goals to lifecycle phases by configuring more Maven plugins and adding them to a life cycle in your POM file. Plugins can contain information that indicates which lifecycle phase to bind a goal to. Note that adding the plugin on its own is not enough information - you need to specify which goal should be executed. If the plugin does not specify the default life cycle it should run, you must also specify the life cycle phase it should run. Maven 24

Add Goals to Phases - Example <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-javadoc-plugin</artifactid> <version>2.10.4</version> <executions> <execution> <phase>site</phase> <goals> <goal>javadoc</goal> </goals> </execution> </executions> </plugin> </plugins> </build> Maven 25

References Maven official site https://maven.apache.org/ Maven in 5 minutes https://maven.apache.org/guides/getting-started/maven-infive-minutes.html Getting started https://maven.apache.org/guides/getting-started/index.html Maven 26

Hands on Session Maven 27

Install Maven Linux (Debian) Command: sudo apt-get install maven Linux (Fedora) Command: sudo yum install maven Mac https://maven.apache.org/install.html Windows https://maven.apache.org/install.html Maven 28

What we are going to do (a) Create a maven project with NetBeans Install the JAR of our project into the Maven local repository mvn install Add a dependecy (log4j) Produce the documentation of our project mvn site Install again the JAR of our project into the Maven local repository mvn install Using Git! Maven 29

What we are going to do (b) Create a test (add JUnit dependency) Add the JaCoCo plugin: <plugin> <groupid>org.jacoco</groupid> <artifactid>jacoco-maven-plugin</artifactid> <version>0.7.9</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> Maven 30