the maven2 revolution

Post on 12-May-2015

941 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

The Maven2 Revolution

A new approach to project development

Dror Bereznitsky

AlphaCSP

Page 2Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Agenda

• What is Maven?

• Core Concepts of Maven 2

– Project Object Model

– The Build Lifecycle

– Maven Plugins

– The dependency Mechanism

– Repositories

• Maven vs. Ant

Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

What is Maven ?

Page 4Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

A Build Survey

� How much time do you spend creating and

managing your build files?

� How many times have you created a new

build script from scratch?

� Can someone new to your project can

immediately build, test, deploy it without

looking at documentation?

Page 5Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

A Build Survey

If you answered :

1. Too much time

2. More than I can remember

3. No way

working withnotyou are probably

Page 6Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

What is Maven?

• Configure your build don’t script it

• Define what to build not how

• Reuse of build logic

• Coherent Organization of Dependencies

A new approach to project development

A development tool – not building blocks

Page 7Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Maven’s Primary Goal

Maven's primary goalprimary goal isto allow a developer to understand the completestate of a projectin the shortest period of time

What is Maven’s project goal ?

Page 8Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

The Primary Goal ..

The way to achieve this goal is:

• Making the build process easy

• Providing a uniform build system

• Providing guidelines for

best practices development

• Providing quality project information

Page 9Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Main Features

• Superior dependency management

• A large repository of libraries and metadata

• Multiple projects handling

• Extensible, easy to write plugins

• Coherent site of project information

• Release management and distribution publication

• Multiple language support – C++, Java …

Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Core Concepts of Maven 2

Page 11Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Project Object Model

• All the information required for the build is

contained in a single POM,

“Project Object Model”, XML file

• The developer provides information about

what is being built and not how

Define What, not How

Page 12Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Project Object Model ..

The POM contains detailed METADATA

information about the project:

– Versioning and configuration management

– Dependencies

– Project structure

– Application and testing resources

And much more …

Page 13Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

A POM Example

<project>

<modelVersion>4.0.0</modelVersion>

<groupId>com.alphacsp</groupId>

<artifactId>my-app</artifactId>

<packaging>jar</packaging>

<version>1.0-SNAPSHOT</version>

<dependencies>

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>3.8.1</version>

<scope>test</scope>

</dependency>

</dependencies>

</project>

All the information required for the build in a single file

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Page 14Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

The Super POM

• Maven's implicitly use its Super POM

• Super POM carries with it all the default

conventions that Maven encourages

• Super POM is the parent of all POMs

• Analog of the Java language's

java.lang.Object class.

How this is possible using a 15 line file?

Page 15Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

The Super POM ..

Page 16Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Standard Directory Layout

• A common directory

layout –

immediately feel at home

in any Maven project

• Based on best practices

• Simplifies the POM

• Can be created using

Archetypes

Page 17Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

The Build Lifecycle

• Software projects generally follow similar

build paths: preparation, compilation,

testing, packaging, installation, etc.

• Maven2 is based around the central concept

of a build lifecycle – the process for

building and distributing a particular artifact

is clearly defined

Page 18Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Phases and Goals

test

package

install

compile

deploy

The build life cycle consists of a series of phaseswhere each phase can perform one or more actions, or goals

Page 19Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

The Build Lifecycle

The lifecycle phase invokes the plugins it needs to complete its task and other dependant lifecycles

Page 20Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

The 80/20 Rule

• Using the default lifecycle mapping, Maven

can build a basic project with little or no

modification – 80% case

• in certain circumstances, a project requires

special tasks in order to build successfully

• Maven can integrate these custom tasks

into the build process through its

extensible plugin framework.

Page 21Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Maven Plugins

Maven is actually a platform that executes plugins within a build life cycle in order to perform the build tasks

Page 22Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Maven Plugins ..

• With most projects, the plugins provided

“out of the box” by Maven are enough.

• More plugins can be found at the Apache

Maven Project and CodeHaus Mojo project.

• If needed, you can write custom plugins to

perform special build tasks.

Page 23Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Maven Mojo

• Plug-in developers only need to make their individual goal, “mojo”, perform a single task.

• A “mojo” has a set of inputs and outputs.

• Plug-ins consist of one or more “mojos”

““mojomojo”” –– maven old java objectmaven old java object

Page 24Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Mojo Example

Page 25Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Maven-Anno-Mojo

Let you use java 5.0 annotations syntax Let you use java 5.0 annotations syntax

instead of doclets for writing your mojosinstead of doclets for writing your mojos

Page 26Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Maven-Anno-Mojo ..

• Inheritance between plugins

• All the benefits of Java 5.0 – generics,

autoboxing …

• Delegation of execution to POJOs

• Natural Ant java tasks integration – not XML

based

Page 27Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

The Dependency Mechanism

Maven excels in dependency management

• Transitive dependencies• Dependency Scope• Dependency Management• Dependency exclusion

Page 28Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

The Dependency Mechanism ..

Just Define your dependencies and forget about

them - maven will do the rest for you:

• Download the dependency

• Resolve all transient dependencies

• Add dependencies to compilation and test

classpath/include path

• Bundle dependencies when needed

Page 29Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

The Dependency Mechanism …

Page 30Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Maven 2 Repositories

Maven repositories shares the same hierarchical structure that hold the build artifacts –

• Group

• Artifact

• Version

Page 31Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Maven 2 Repositories ..

There are two types of repositories:

• Remote - any type of repository, accessed by a

variety of protocols (file://, http://...).

http://repo1.maven.org is the central repository

• Local - a local cache of the

remote downloads and the latest build artifacts

Usually at : ${user.home}/.m2/repository

Page 32Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Remote Repository

Page 33Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Local Repository

Page 34Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Site Generation

Maven is famous for its Site generation that includes:

� a reference to the build server

� Javadoc

� source XRef

� issue tracking reference

� test and quality reports

Page 35Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Site examples – code coverage

Page 36Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Site examples – Surefire report

Page 37Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Site – Custom Look & Feel

Page 38Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

IDE Support

Maven has some neat plug-ins for IDE project

generation, including:

– IntelliJ IDEA

– Eclipse

– Netbeans

Page 39Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

IDE Support ..

• The IDE projects created include:

– All the dependencies 3rd party/internal

– Dependency source linking

• The created project is ready to compile, test

, debug and run.

Page 40Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Multiple Language Support

• Maven supports

multiple development

languages such as

Java , C++, C, C#,

Fortran and more.

• Different languages

has their own

common standard

layout.

Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Maven vs. Ant

Page 42Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Maven vs. Ant

OK, but Ant is working fine !

•Ant provides building blocks for a toolset - Maven provides a working tool

•Ant has no build lifecycle, repositories, standard project layout, dependency management …you have to do it by yourself !

•Ant scripts become complex

•Ant scripts are not reusable – promotes duplication

•Ant is becoming legacy and not moving fast ahead

Page 43Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

MyApp – Ant Build File – 141 lines

141 Lines of code !!!

Page 44Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

MyApp -Maven Build File – 17 lines

17 Lines of code

Page 45Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Maven vs. Ant ..

From our experience in Ant migration

projects there is a 1:30 ratio in the number of lines of code between Maven2 and Ant.

Page 46Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

Your Turn Now

Q & A

Copyright AlphaCSP Israel 2006 - The Ultimate Development Environment Seminar

top related