BMO - Intelligent Projects with Maven

Mert Çalışkan
Mert ÇalışkanSoftware Stylist @ T2, Oracle Java Champion, Author, JUG Leader, Lecturer at Hacettepe University em T2 Yazılım
Intelligent Projects with
Maven


We’ll examine Maven framework with its architecture and
create some sample projects!
Mert ÇALIŞKAN
Jan 2014
@mertcal
Mert ÇALIŞKAN
• ’02 Hacettepe Graduate
• Lecturer @ Hacettepe
• 10+Years of Enterprise Java Experience
• Coder @ t2.com.tr
• Author
• Open Source Software Advocate
• Founder of Ankara JUG
• Linkedin Profile available @

bit.ly/mertcaliskan
• @mertcal
My Books
Details available at http://amazon.com/author/mert
How many of you heard
about Maven?
Or using it?
• A project management framework from ASF.
• It’s a Uniform Build System.
• Making the build as easy as possible.
• Comprehensive model for software projects.
Maven is…
• Convention over Configuration 

(konfigurasyon yerine kurallar)
• Common Interfaces

The time of build engineers is over

Stop building the build and focus on development !
• Dependency Management

Public repositories
• Plugin Architecture
• Documentation

Generate documentation, reports ... 

What Maven provides
• You need JDK (not the JRE).
• Just download the binary from

http://maven.apache.org/download.cgi.
• Current latest version is 3.2.5.
• 3.2.x branch correlates with JDK6 while 3.1.x sticks
with JDK5
• Open it up to a folder and add it to the path of the
OS / EnvironmentVariable.
Installing Maven
To understand Maven
one first need to
understand
the
Project Object Model
(POM)
• It is what makes your project a Maven Project.
• It’s an XML file.
• Not just for building the project; but also,

project’s relationship, list of team members,
license, SCM and etc.
• Not only for Java projects
• you can build FLEX code with appropriate
plugins
• you can build Microsoft binaries from C# code
POM
Anatomy of POM
<project ...>
<parent />
<groupId /> <artifactId /> <version />
<packaging />
<developers /> <contributors />
<scm>... </scm>

<build>
<plugins>....</plugins>
</build>

<dependencies>....</dependencies>
<repositories>....</repositories>
<pluginRepositories>... </pluginRepositories>
<profiles>...</profiles>
<reporting>... </reporting>
</project>
Simplest POM
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>tr.org.bimo</groupId>
<artifactId>MavenApp</artifactId>
<version>1.0.0</version>
</project>
$ mvn install
compile code
run tests
package as jar
deploy to local repo}
Simplest POM
• GAV (groupid - artifactid - version) is the unique
identifier for the project.
• They are also called as the coordinates.
• groupid: is the identifier for a collection of related
modules. It’s more like a hierarchy that starts with the
organization and then move on with the specific
project group. (tr.org.bimo)
• artifactid: is the unique identifier or the simple name
of the module within a group (MavenApp)
• version: identifier for the build number of the project.
Question here is

How is that possible with 6 lines
of XML?
Where do I define the source
folders, test folders and all other
stuff ?
• Same analogy with java.lang.Object
• usr/share/Java/maven/lib/maven-model-
builder-3.2.5.jar:org/apache/maven/model/
pom-4.0.0.xml
• Standard directory layout
• Repo def. for http://repo1.maven.org/maven2
• To see the merged POM: 

mvn help:effective-pom
Super POM
Let’s create a 

Maven Project
• We’ll be using Eclipse Luna
• Version: IDE for JavaEE Developers is shipping with
Maven Plugins. (Beware of the embedded maven
bundled w/ Eclipse.)
• We’ll also create a project with the archetype soon.
• 3 built-in Life Cycles 

default: handles project deployment

clean: clean project files generated by a build

site: generate project’s site doc.
• Each lifecycle consists of phases in specific order.
• Zero or more goals attached to each phase.
Build LifeCycle
• Process for building and distributing an
artefact is clearly defined.
Build LifeCycle
default
integration-test
validate
compile
test
verify
install
deploy
mvn integration -test
default
integration-test
validate
compile
test
verify
install
deploy
mvn phase
mvn phase:goal
mvn phase phase:goal
mvn phase:goal phase:goal
integration-test
validate
compile
test
Build LifeCycle
• 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.These tests should not
require the code be packaged or deployed
• package - take the compiled code and package it in its
distributable format, such as a JAR.
Build LifeCycle
• integration-test - process and deploy the package if
necessary into an environment where integration
tests can be run
• verify - run any checks to verify the package is valid
and meets quality criteria
• install - install the package into the local repository,
for use as a dependency in other projects locally
• deploy - done in an integration or release
environment, copies the final package to the remote
repository for sharing with other developers and
projects.
default - full bundle (21 steps)
validate
Validates whether project is correct and all necessary information
is available to complete the build process.
initialize Initialises build state, for example set properties.
generate-sources Generate any source code to be included in compilation phase.
process-sources Process the source code, for example, filter any value.
generate-resources Generate resources to be included in the package.
process-resources
Copy and process the resources into the destination directory,
ready for packaging phase.
compile Compile the source code of the project.
process-classes
Post-process the generated files from compilation, for example to
do bytecode enhancement/optimization on Java classes.
generate-test-
sources
Generate any test source code to be included in compilation
phase.
process-test-
sources
Process the test source code, for example, filter any values.
test-compile Compile the test source code into the test destination directory.
process-test-
classes
Process the generated files from test code file compilation.
default - cont’d
test Run tests using a suitable unit testing framework.
prepare-package
Perform any operations necessary to prepare a package before
the actual packaging.
package
Take the compiled code and package it in its distributable format,
such as a JAR, WAR, or EAR file.
pre-integration-test
Perform actions required before integration tests are executed.
For example, setting up the required environment.
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. For example, cleaning up the environment.
verify
Run any check-ups to verify the package is valid and meets
quality criterias.
install
Install the package into the local repository, which can be used
as a dependency in other projects locally.
deploy
Copies the final package to the remote repository for sharing
with other developers and projects.
• It’s where Maven can ease the development when
you have hundreds of modules.
• You may also depend on external frameworks and
maven will fetch them from repositories.
• It happens with the Coordinates ! (GAV factor)











Dependency Mechanism
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
<scope>compile</scope>
<optional>false</optional>
</dependency>
• Transitive Dependencies are introduced with
Maven version 2.0.
• It allows you get the libraries that your own
dependencies require and include them
automatically.You don’t need to take care of those
explicitly.
• There is no limit to the number of levels on
dependencies.
Transitive Dependencies
• If projectX depends on
projectY and 

projectY depends on projectZ, 



the owner of projectX can
define an exclusion on projectZ 

for not to fetch it while fetching
projectY.
Dependency Exclusion
X
Y
Z
Usage of <exclusion>
<dependency>
<groupId>mycompany</groupId>
<artifactId>myproject</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>mycompany</groupId>
<artifactId>myotherproject</artifactId>
</exclusion>
</exclusions>
</dependency>
• Let’s say projectY releases itself
and mark its dependency on
projectZ as optional.When
projectX depends on the
projectY, project X will only
depend on theY but not the Z.
But it may also add the Z as a
dependency if needed.
Optional Dependencies
X
Y
Z
(optional)
Usage of <optional>
<dependency>
<groupId>mycompany</groupId>
<artifactId>projectZ</artifactId>
<version>1.0</version>
<optional>true</optional>
</dependency>
• ProjectY defines ProjectZ as below with optional
dep.
Sample <dependencies>
<dependencies>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-core</artifactId>

<version>4.1.2.RELEASE</version>

</dependency>

<dependency>

<groupId>org.hibernate</groupId>

<artifactId>hibernate-core</artifactId>

<version>4.3.2.Final</version>

</dependency>

</dependencies>
Scope for Dependencies
compile
testruntime
provided
system import
C T RCompile
Classpaths
Test Runtime
Scope for Dependencies
compile default scope, compile scoped dependencies will be in classpathCTR
provided
similar to the compile, artefact should be provided by 

JDK / container @ runtimeCT
not needed for compilation but need @ runtimeruntimeTR
testT dependency only needed for test compilation & execution
with maven 2.0.9...dependency to be replaced with
the dependencies in that POM's
<dependencyManagement> section.
import---
systemCT same as provided, but artefact should be provided
explicitly with <systemPath />
Classpath
Versioning and Ranges
<major>.<minor>.<incremental>-<buildnumber>.<qualifier>
MajorVersion: 1.2
MinorVersion: 1.3
IncrementalVersion: 1.3.1
BuildNumber: 1.3.2-12
Qualifier: 1.2-beta-2
1.2-beta-2 < 1.2
All versions with a qualifier are older than the same version
without a qualifier.
Identical versions with different qualifier fields are compared by
using basic string comparison.
1.2-beta-2 is >1.2-alpha-6
Versioning and Ranges
• Maven 2.x was supporting meta-versions like LATEST
and RELEASE to specify special versions.
• But for the sake of reproducible builds, Maven 3.x no
longer supports usage of these meta-versions in
POM.
(, ) - Exclusive

[, ] - Inclusive
<version>[3.8 , 4.12)</version>
<version>[3.8]</version>
<version>[ , 3.8]</version>Dependency
Mediation
• Ranges can be defined as exclusive and inclusive.
Release and Snapshot
Versioning
• Snapshot versioning: Used by the projects during
development as it implies that the project is still
under development and it may change.



<version>0.0.2-SNAPSHOT</version>
• Release versioning: It’s the versioning that is assumed
never to change. Only to be used for a single state of
the project when it is released then updated to a
next snapshot. 



<version>0.0.1</version>
Archetypes
• Templates for Maven projects
• Descriptor XML files +Velocity templates
• To create a Maven project:
mvn archetype:generate -DgroupId=tr.org.bimo -DartifactId=sampleApp -
Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.apache.maven.archetypes -
DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.0
Let’s create a 

Maven Project
with an archetype
• By using an archetype from JBOSS repository
• https://repository.jboss.org/nexus/content/
repositories/releases/archetype-catalog.xml
• We will have Domain classes, Web Pages, in
memory database, REST services and etc.
(G:A:V) org.jboss.spring.archetyes : jboss-spring-mvc-archetype : 1.0.0.Final
How Maven resolve
versions?
A : A : 1.0
B : B : 1.0C : C : 1.0
B : B : 2.0
commons-logging
commons-logging
1.0.1
commons-logging
commons-logging
1.1.1
commons-logging
commons-logging
1.1.1
D : D : 1.0
commons-logging
commons-logging
1.0.4
Which B will
Maven choose?
B:2.0
the highest one?
G:A:V
A : A : 1.0
B : B : 1.0C : C : 1.0
B : B : 2.0
commons-logging
commons-logging
1.0.1
commons-logging
commons-logging
1.1.1
commons-logging
commons-logging
1.1.1
D : D : 1.0
commons-logging
commons-logging
1.0.4
Maven will choose 

the closest one.
A : A : 1.0
B : B : 1.0C : C : 1.0
B : B : 2.0
commons-logging
commons-logging
1.0.1
commons-logging
commons-logging
1.1.1
commons-logging
commons-logging
1.1.1
D : D : 1.0
commons-logging
commons-logging
1.0.4
Which
commons-logging?
??
?
?
A : A : 1.0
B : B : 1.0C : C : 1.0
B : B : 2.0
commons-logging
commons-logging
1.0.1
commons-logging
commons-logging
1.1.1
commons-logging
commons-logging
1.1.1
D : D : 1.0
commons-logging
commons-logging
1.0.4
The Sequential first at the same distance…
The Final Graph…
A : A : 1.0
B : B : 1.0C : C : 1.0
commons-logging
commons-logging
1.0.4
D : D : 1.0
Question:
Project A will work in the end 

OR not?
A : A : 1.0
B : B : 1.0C : C : 1.0
commons-logging
commons-logging
1.0.4
D : D : 1.0
Managing
Projects’ Dependencies
Inheritance
ParentApp
ChildApp
<<extends>>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>tr.org.bimo</groupId>
<artifactId>ParentApp</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>tr.org.bimo</groupId>
<artifactId>ChildApp</artifactId>
<version>1.0.0-SNAPSHOT</version>
</project>
Aggregation
ProjectA ProjectB ProjectC
<<depends>> <<depends>>
root $ cd ProjectC
projectC $ mvn compile
projectC $ cd ..
root $ cd ProjectB
projectB $ mvn compile
projectB $ cd ..
root $ cd ProjectA
projectA $ mvn compile
} 8 lines !!!
Aggregation
modulesapp
ProjectA ProjectB
ProjectC
<<module>>
<<module>>
<<module>>
root $ cd modulesapp
modulesapp $ mvn compile
modulesapp:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>tr.org.bimo</groupId>
<artifactId>modulesapp</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>modulesapp</name>
<modules>
<module>projectA</module>
<module>projectB</module>
<module>projectC</module>
</modules>
</project>
Question here is:
With mvn compile
which module will compile
first?
<modules>
<module>projectA</module>
<module>projectB</module>
<module>projectC</module>
</modules>
Repositories
• To manage build artefacts and dependencies
• local or remote repositories
• Can store jar, war, ear, ejb, rar ....
• Maven looks to at least 2 repository if none
specified 

- local one (under user home)

- http://repo.maven.apache.org/maven2 

(defined in uber-pom)
• Release & Snapshot repositories
Repositories
<repository>
<id>jboss-repo</id>
<name>The Release JBoss maven repo</name>
<url>http://repository.jboss.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>jboss-snapshot-repo</id>
<name>The Snapshot JBoss maven repo</name>
<url>http://snapshots.jboss.org/maven2</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
Plugins
• Plugin-oriented Architecture

plugin for even compiling the code..
• A maven artefact w/ descriptor (plugin.xml) and one or more MOJOs
• A MOJO is a Maven plain Old Java Object. Each mojo is an executable
goal in Maven, and a plugin is a distribution of one or more related
MOJOs.
• In short, a MOJO is a maven goal, to extend functionality not already
found in Maven.
• Plexus as its IoC. (Guice also introduced with version 3.x)

Why not Spring?
• List of plugins supported by Maven Project.

https://maven.apache.org/plugins
Plugin Development
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/
maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tr.org.bimo</groupId>
<artifactId>hello-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Plugin Development
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
</dependency>
</dependencies>
</project>
Plugin Development
Mojo Code
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
@Mojo( name = "sayhi")
public class GreetingMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
getLog().info( "Hello world." );
}
}
Use the plugin
<build>
<plugins>
<plugin>
<groupId>tr.org.bimo</groupId>
<artifactId>hello-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>sayhi</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
What we did w/ plugins in
PrimeFaces
• Component Class
• Tag Handler Class
• Declare Component,Tag, Renderer classes in faces-config.xml
• Declare facelet tag definition
• Declare tld tag definition
• maven-jsf-plugin
• plugin available @ 

http://repository.primefaces.org/org/primefaces/maven-jsf-plugin
settings.xml
• Maven provides 2 settings file,
• Local settings.xml at %USER_HOME%/.m2/settings.xml
• Global settings.xml at %M2_HOME%/conf/settings.xml
• These files are not bundled with Maven project and don’t get
distributed.
• If both files exist, their contents get merged.
• Local settings.xml overrides the global one.
And not to forget that…
Maven is our precious…
Thank you..!
1 de 59

Recomendados

Jdc 2010 - Maven, Intelligent Projects por
Jdc 2010 - Maven, Intelligent ProjectsJdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent ProjectsMert Çalışkan
1.4K visualizações72 slides
Intelligent Projects with Maven - DevFest Istanbul por
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulMert Çalışkan
1.3K visualizações58 slides
jDays2015 - JavaEE vs. Spring Smackdown por
jDays2015 - JavaEE vs. Spring SmackdownjDays2015 - JavaEE vs. Spring Smackdown
jDays2015 - JavaEE vs. Spring SmackdownMert Çalışkan
3K visualizações50 slides
MicroProfile for MicroServices por
MicroProfile for MicroServicesMicroProfile for MicroServices
MicroProfile for MicroServicesMert Çalışkan
818 visualizações47 slides
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI por
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDIMigrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDIMario-Leander Reimer
3.3K visualizações42 slides
Spring - CDI Interop por
Spring - CDI InteropSpring - CDI Interop
Spring - CDI InteropRay Ploski
6.5K visualizações36 slides

Mais conteúdo relacionado

Mais procurados

JPQL/ JPA Activity 1 por
JPQL/ JPA Activity 1JPQL/ JPA Activity 1
JPQL/ JPA Activity 1SFI
684 visualizações27 slides
MicroProfile: Optimizing Java EE for a Microservices Architecture por
MicroProfile: Optimizing Java EE for a Microservices ArchitectureMicroProfile: Optimizing Java EE for a Microservices Architecture
MicroProfile: Optimizing Java EE for a Microservices Architecturejclingan
402 visualizações27 slides
Java EE and Spring Side-by-Side por
Java EE and Spring Side-by-SideJava EE and Spring Side-by-Side
Java EE and Spring Side-by-SideReza Rahman
54.8K visualizações32 slides
Micronaut: A new way to build microservices por
Micronaut: A new way to build microservicesMicronaut: A new way to build microservices
Micronaut: A new way to build microservicesLuram Archanjo
371 visualizações30 slides
Faster java ee builds with gradle [con4921] por
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Ryan Cuprak
2.4K visualizações64 slides
Running Spring Boot Applications as GraalVM Native Images por
Running Spring Boot Applications as GraalVM Native ImagesRunning Spring Boot Applications as GraalVM Native Images
Running Spring Boot Applications as GraalVM Native ImagesVMware Tanzu
7.2K visualizações49 slides

Mais procurados(19)

JPQL/ JPA Activity 1 por SFI
JPQL/ JPA Activity 1JPQL/ JPA Activity 1
JPQL/ JPA Activity 1
SFI684 visualizações
MicroProfile: Optimizing Java EE for a Microservices Architecture por jclingan
MicroProfile: Optimizing Java EE for a Microservices ArchitectureMicroProfile: Optimizing Java EE for a Microservices Architecture
MicroProfile: Optimizing Java EE for a Microservices Architecture
jclingan402 visualizações
Java EE and Spring Side-by-Side por Reza Rahman
Java EE and Spring Side-by-SideJava EE and Spring Side-by-Side
Java EE and Spring Side-by-Side
Reza Rahman54.8K visualizações
Micronaut: A new way to build microservices por Luram Archanjo
Micronaut: A new way to build microservicesMicronaut: A new way to build microservices
Micronaut: A new way to build microservices
Luram Archanjo371 visualizações
Faster java ee builds with gradle [con4921] por Ryan Cuprak
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
Ryan Cuprak2.4K visualizações
Running Spring Boot Applications as GraalVM Native Images por VMware Tanzu
Running Spring Boot Applications as GraalVM Native ImagesRunning Spring Boot Applications as GraalVM Native Images
Running Spring Boot Applications as GraalVM Native Images
VMware Tanzu7.2K visualizações
Peering Inside the Black Box: A Case for Observability por VMware Tanzu
Peering Inside the Black Box: A Case for ObservabilityPeering Inside the Black Box: A Case for Observability
Peering Inside the Black Box: A Case for Observability
VMware Tanzu166 visualizações
Apache DeltaSpike por os890
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpike
os8909.5K visualizações
Node.js Development with Apache NetBeans por Ryan Cuprak
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
Ryan Cuprak5.5K visualizações
MicroProfile Devoxx.us por jclingan
MicroProfile Devoxx.usMicroProfile Devoxx.us
MicroProfile Devoxx.us
jclingan329 visualizações
Testing Java EE apps with Arquillian por Ivan Ivanov
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
Ivan Ivanov3K visualizações
Maven por feng lee
MavenMaven
Maven
feng lee1.8K visualizações
Why jakarta ee matters (ConFoo 2021) por Ryan Cuprak
Why jakarta ee matters (ConFoo 2021)Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)
Ryan Cuprak221 visualizações
Spring Native and Spring AOT por VMware Tanzu
Spring Native and Spring AOTSpring Native and Spring AOT
Spring Native and Spring AOT
VMware Tanzu1.6K visualizações
Developing modern java web applications with java ee 7 and angular js por Shekhar Gulati
Developing modern java web applications with java ee 7 and angular jsDeveloping modern java web applications with java ee 7 and angular js
Developing modern java web applications with java ee 7 and angular js
Shekhar Gulati3.2K visualizações
Java EE 8 Update por Ryan Cuprak
Java EE 8 UpdateJava EE 8 Update
Java EE 8 Update
Ryan Cuprak9.6K visualizações
Liferay maven sdk por Mika Koivisto
Liferay maven sdkLiferay maven sdk
Liferay maven sdk
Mika Koivisto3.2K visualizações
Spring Mvc,Java, Spring por ifnu bima
Spring Mvc,Java, SpringSpring Mvc,Java, Spring
Spring Mvc,Java, Spring
ifnu bima2.1K visualizações

Destaque

Using Maven 2 por
Using Maven 2Using Maven 2
Using Maven 2andyhot
2.8K visualizações15 slides
Goal4d por
Goal4dGoal4d
Goal4dandyhot
1.8K visualizações34 slides
Cours design pattern m youssfi partie 5 adapter por
Cours design pattern m youssfi partie 5 adapterCours design pattern m youssfi partie 5 adapter
Cours design pattern m youssfi partie 5 adapterENSET, Université Hassan II Casablanca
11.8K visualizações9 slides
Cours design pattern m youssfi partie 7 facade bridge flyweight por
Cours design pattern m youssfi partie 7 facade bridge flyweightCours design pattern m youssfi partie 7 facade bridge flyweight
Cours design pattern m youssfi partie 7 facade bridge flyweightENSET, Université Hassan II Casablanca
16.6K visualizações33 slides
Cours design pattern m youssfi partie 2 observer por
Cours design pattern m youssfi partie 2 observerCours design pattern m youssfi partie 2 observer
Cours design pattern m youssfi partie 2 observerENSET, Université Hassan II Casablanca
16.5K visualizações44 slides
Cours design pattern m youssfi partie 8 stat, template method, command , medi... por
Cours design pattern m youssfi partie 8 stat, template method, command , medi...Cours design pattern m youssfi partie 8 stat, template method, command , medi...
Cours design pattern m youssfi partie 8 stat, template method, command , medi...ENSET, Université Hassan II Casablanca
18.7K visualizações47 slides

Destaque(20)

Using Maven 2 por andyhot
Using Maven 2Using Maven 2
Using Maven 2
andyhot2.8K visualizações
Goal4d por andyhot
Goal4dGoal4d
Goal4d
andyhot1.8K visualizações
An introduction to Maven por Joao Pereira
An introduction to MavenAn introduction to Maven
An introduction to Maven
Joao Pereira7.9K visualizações
Présentation Maven por SOAT
Présentation MavenPrésentation Maven
Présentation Maven
SOAT4.3K visualizações

Similar a BMO - Intelligent Projects with 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
Jenkins advance topic por
Jenkins advance topicJenkins advance topic
Jenkins advance topicGourav Varma
182 visualizações29 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
Jenkins advance topic por
Jenkins advance topicJenkins advance topic
Jenkins advance topicKalkey
70 visualizações29 slides
Introduction to maven por
Introduction to mavenIntroduction to maven
Introduction to mavenManos Georgopoulos
1.2K visualizações24 slides

Similar a BMO - Intelligent Projects with 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
Jenkins advance topic por Gourav Varma
Jenkins advance topicJenkins advance topic
Jenkins advance topic
Gourav Varma182 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
Jenkins advance topic por Kalkey
Jenkins advance topicJenkins advance topic
Jenkins advance topic
Kalkey70 visualizações
Introduction to maven por Manos Georgopoulos
Introduction to mavenIntroduction to maven
Introduction to maven
Manos Georgopoulos1.2K visualizações
tools cli java por TiNguyn863920
tools cli javatools cli java
tools cli java
TiNguyn8639204 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
Maven Basics - Explained por Smita Prasad
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
Smita Prasad1.1K visualizações
S/W Design and Modularity using Maven por Scheidt & Bachmann
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
Scheidt & Bachmann2.9K visualizações
Build your android app with gradle por Swain Loda
Build your android app with gradleBuild your android app with gradle
Build your android app with gradle
Swain Loda186 visualizações
Developing Liferay Plugins with Maven por Mika Koivisto
Developing Liferay Plugins with MavenDeveloping Liferay Plugins with Maven
Developing Liferay Plugins with Maven
Mika Koivisto11.7K visualizações
Mavennotes.pdf por AnkurSingh656748
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
AnkurSingh65674810 visualizações
Maven in mulesoft por venkata20k
Maven in mulesoftMaven in mulesoft
Maven in mulesoft
venkata20k142 visualizações
Maven basic concept por Ming-Sian Lin
Maven basic conceptMaven basic concept
Maven basic concept
Ming-Sian Lin843 visualizações
Session 2 por gayathiry
Session 2Session 2
Session 2
gayathiry167 visualizações
Session 2 por gayathiry
Session 2Session 2
Session 2
gayathiry162 visualizações
4 maven junit por Honnix Liang
4 maven junit4 maven junit
4 maven junit
Honnix Liang692 visualizações
An introduction to maven gradle and sbt por Fabio Fumarola
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
Fabio Fumarola8.2K visualizações

Mais de Mert Çalışkan

JavaOne - 10 Tips for Java EE 7 with PrimeFaces por
JavaOne - 10 Tips for Java EE 7 with PrimeFacesJavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesMert Çalışkan
27.1K visualizações41 slides
Better Career with Java por
Better Career with JavaBetter Career with Java
Better Career with JavaMert Çalışkan
1.3K visualizações52 slides
Test Infected por
Test InfectedTest Infected
Test InfectedMert Çalışkan
1K visualizações68 slides
Gelecex - Maven ile Akilli Projeler por
Gelecex - Maven ile Akilli ProjelerGelecex - Maven ile Akilli Projeler
Gelecex - Maven ile Akilli ProjelerMert Çalışkan
388 visualizações57 slides
Fikrim Acik Kodum Acik por
Fikrim Acik Kodum AcikFikrim Acik Kodum Acik
Fikrim Acik Kodum AcikMert Çalışkan
1.6K visualizações35 slides
Enterprise Java Web Application Frameworks Sample Stack Implementation por
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack ImplementationMert Çalışkan
4.3K visualizações39 slides

Mais de Mert Çalışkan(6)

JavaOne - 10 Tips for Java EE 7 with PrimeFaces por Mert Çalışkan
JavaOne - 10 Tips for Java EE 7 with PrimeFacesJavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
Mert Çalışkan27.1K visualizações
Better Career with Java por Mert Çalışkan
Better Career with JavaBetter Career with Java
Better Career with Java
Mert Çalışkan1.3K visualizações
Test Infected por Mert Çalışkan
Test InfectedTest Infected
Test Infected
Mert Çalışkan1K visualizações
Gelecex - Maven ile Akilli Projeler por Mert Çalışkan
Gelecex - Maven ile Akilli ProjelerGelecex - Maven ile Akilli Projeler
Gelecex - Maven ile Akilli Projeler
Mert Çalışkan388 visualizações
Fikrim Acik Kodum Acik por Mert Çalışkan
Fikrim Acik Kodum AcikFikrim Acik Kodum Acik
Fikrim Acik Kodum Acik
Mert Çalışkan1.6K visualizações
Enterprise Java Web Application Frameworks Sample Stack Implementation por Mert Çalışkan
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack Implementation
Mert Çalışkan4.3K visualizações

BMO - Intelligent Projects with Maven

  • 1. Intelligent Projects with Maven 
 We’ll examine Maven framework with its architecture and create some sample projects! Mert ÇALIŞKAN Jan 2014 @mertcal
  • 2. Mert ÇALIŞKAN • ’02 Hacettepe Graduate • Lecturer @ Hacettepe • 10+Years of Enterprise Java Experience • Coder @ t2.com.tr • Author • Open Source Software Advocate • Founder of Ankara JUG • Linkedin Profile available @
 bit.ly/mertcaliskan • @mertcal
  • 3. My Books Details available at http://amazon.com/author/mert
  • 4. How many of you heard about Maven? Or using it?
  • 5. • A project management framework from ASF. • It’s a Uniform Build System. • Making the build as easy as possible. • Comprehensive model for software projects. Maven is…
  • 6. • Convention over Configuration 
 (konfigurasyon yerine kurallar) • Common Interfaces
 The time of build engineers is over
 Stop building the build and focus on development ! • Dependency Management
 Public repositories • Plugin Architecture • Documentation
 Generate documentation, reports ... 
 What Maven provides
  • 7. • You need JDK (not the JRE). • Just download the binary from
 http://maven.apache.org/download.cgi. • Current latest version is 3.2.5. • 3.2.x branch correlates with JDK6 while 3.1.x sticks with JDK5 • Open it up to a folder and add it to the path of the OS / EnvironmentVariable. Installing Maven
  • 8. To understand Maven one first need to understand the Project Object Model (POM)
  • 9. • It is what makes your project a Maven Project. • It’s an XML file. • Not just for building the project; but also,
 project’s relationship, list of team members, license, SCM and etc. • Not only for Java projects • you can build FLEX code with appropriate plugins • you can build Microsoft binaries from C# code POM
  • 10. Anatomy of POM <project ...> <parent /> <groupId /> <artifactId /> <version /> <packaging /> <developers /> <contributors /> <scm>... </scm>
 <build> <plugins>....</plugins> </build>
 <dependencies>....</dependencies> <repositories>....</repositories> <pluginRepositories>... </pluginRepositories> <profiles>...</profiles> <reporting>... </reporting> </project>
  • 12. Simplest POM • GAV (groupid - artifactid - version) is the unique identifier for the project. • They are also called as the coordinates. • groupid: is the identifier for a collection of related modules. It’s more like a hierarchy that starts with the organization and then move on with the specific project group. (tr.org.bimo) • artifactid: is the unique identifier or the simple name of the module within a group (MavenApp) • version: identifier for the build number of the project.
  • 13. Question here is
 How is that possible with 6 lines of XML? Where do I define the source folders, test folders and all other stuff ?
  • 14. • Same analogy with java.lang.Object • usr/share/Java/maven/lib/maven-model- builder-3.2.5.jar:org/apache/maven/model/ pom-4.0.0.xml • Standard directory layout • Repo def. for http://repo1.maven.org/maven2 • To see the merged POM: 
 mvn help:effective-pom Super POM
  • 15. Let’s create a 
 Maven Project • We’ll be using Eclipse Luna • Version: IDE for JavaEE Developers is shipping with Maven Plugins. (Beware of the embedded maven bundled w/ Eclipse.) • We’ll also create a project with the archetype soon.
  • 16. • 3 built-in Life Cycles 
 default: handles project deployment
 clean: clean project files generated by a build
 site: generate project’s site doc. • Each lifecycle consists of phases in specific order. • Zero or more goals attached to each phase. Build LifeCycle • Process for building and distributing an artefact is clearly defined.
  • 18. mvn integration -test default integration-test validate compile test verify install deploy mvn phase mvn phase:goal mvn phase phase:goal mvn phase:goal phase:goal integration-test validate compile test
  • 19. Build LifeCycle • 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.These tests should not require the code be packaged or deployed • package - take the compiled code and package it in its distributable format, such as a JAR.
  • 20. Build LifeCycle • integration-test - process and deploy the package if necessary into an environment where integration tests can be run • verify - run any checks to verify the package is valid and meets quality criteria • install - install the package into the local repository, for use as a dependency in other projects locally • deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
  • 21. default - full bundle (21 steps) validate Validates whether project is correct and all necessary information is available to complete the build process. initialize Initialises build state, for example set properties. generate-sources Generate any source code to be included in compilation phase. process-sources Process the source code, for example, filter any value. generate-resources Generate resources to be included in the package. process-resources Copy and process the resources into the destination directory, ready for packaging phase. compile Compile the source code of the project. process-classes Post-process the generated files from compilation, for example to do bytecode enhancement/optimization on Java classes. generate-test- sources Generate any test source code to be included in compilation phase. process-test- sources Process the test source code, for example, filter any values. test-compile Compile the test source code into the test destination directory. process-test- classes Process the generated files from test code file compilation.
  • 22. default - cont’d test Run tests using a suitable unit testing framework. prepare-package Perform any operations necessary to prepare a package before the actual packaging. package Take the compiled code and package it in its distributable format, such as a JAR, WAR, or EAR file. pre-integration-test Perform actions required before integration tests are executed. For example, setting up the required environment. 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. For example, cleaning up the environment. verify Run any check-ups to verify the package is valid and meets quality criterias. install Install the package into the local repository, which can be used as a dependency in other projects locally. deploy Copies the final package to the remote repository for sharing with other developers and projects.
  • 23. • It’s where Maven can ease the development when you have hundreds of modules. • You may also depend on external frameworks and maven will fetch them from repositories. • It happens with the Coordinates ! (GAV factor)
 
 
 
 
 
 Dependency Mechanism <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.7</version> <scope>compile</scope> <optional>false</optional> </dependency>
  • 24. • Transitive Dependencies are introduced with Maven version 2.0. • It allows you get the libraries that your own dependencies require and include them automatically.You don’t need to take care of those explicitly. • There is no limit to the number of levels on dependencies. Transitive Dependencies
  • 25. • If projectX depends on projectY and 
 projectY depends on projectZ, 
 
 the owner of projectX can define an exclusion on projectZ 
 for not to fetch it while fetching projectY. Dependency Exclusion X Y Z
  • 27. • Let’s say projectY releases itself and mark its dependency on projectZ as optional.When projectX depends on the projectY, project X will only depend on theY but not the Z. But it may also add the Z as a dependency if needed. Optional Dependencies X Y Z (optional)
  • 30. Scope for Dependencies compile testruntime provided system import C T RCompile Classpaths Test Runtime
  • 31. Scope for Dependencies compile default scope, compile scoped dependencies will be in classpathCTR provided similar to the compile, artefact should be provided by 
 JDK / container @ runtimeCT not needed for compilation but need @ runtimeruntimeTR testT dependency only needed for test compilation & execution with maven 2.0.9...dependency to be replaced with the dependencies in that POM's <dependencyManagement> section. import--- systemCT same as provided, but artefact should be provided explicitly with <systemPath /> Classpath
  • 32. Versioning and Ranges <major>.<minor>.<incremental>-<buildnumber>.<qualifier> MajorVersion: 1.2 MinorVersion: 1.3 IncrementalVersion: 1.3.1 BuildNumber: 1.3.2-12 Qualifier: 1.2-beta-2 1.2-beta-2 < 1.2 All versions with a qualifier are older than the same version without a qualifier. Identical versions with different qualifier fields are compared by using basic string comparison. 1.2-beta-2 is >1.2-alpha-6
  • 33. Versioning and Ranges • Maven 2.x was supporting meta-versions like LATEST and RELEASE to specify special versions. • But for the sake of reproducible builds, Maven 3.x no longer supports usage of these meta-versions in POM. (, ) - Exclusive
 [, ] - Inclusive <version>[3.8 , 4.12)</version> <version>[3.8]</version> <version>[ , 3.8]</version>Dependency Mediation • Ranges can be defined as exclusive and inclusive.
  • 34. Release and Snapshot Versioning • Snapshot versioning: Used by the projects during development as it implies that the project is still under development and it may change.
 
 <version>0.0.2-SNAPSHOT</version> • Release versioning: It’s the versioning that is assumed never to change. Only to be used for a single state of the project when it is released then updated to a next snapshot. 
 
 <version>0.0.1</version>
  • 35. Archetypes • Templates for Maven projects • Descriptor XML files +Velocity templates • To create a Maven project: mvn archetype:generate -DgroupId=tr.org.bimo -DartifactId=sampleApp - Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.apache.maven.archetypes - DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.0
  • 36. Let’s create a 
 Maven Project with an archetype • By using an archetype from JBOSS repository • https://repository.jboss.org/nexus/content/ repositories/releases/archetype-catalog.xml • We will have Domain classes, Web Pages, in memory database, REST services and etc. (G:A:V) org.jboss.spring.archetyes : jboss-spring-mvc-archetype : 1.0.0.Final
  • 38. A : A : 1.0 B : B : 1.0C : C : 1.0 B : B : 2.0 commons-logging commons-logging 1.0.1 commons-logging commons-logging 1.1.1 commons-logging commons-logging 1.1.1 D : D : 1.0 commons-logging commons-logging 1.0.4 Which B will Maven choose? B:2.0 the highest one? G:A:V
  • 39. A : A : 1.0 B : B : 1.0C : C : 1.0 B : B : 2.0 commons-logging commons-logging 1.0.1 commons-logging commons-logging 1.1.1 commons-logging commons-logging 1.1.1 D : D : 1.0 commons-logging commons-logging 1.0.4 Maven will choose 
 the closest one.
  • 40. A : A : 1.0 B : B : 1.0C : C : 1.0 B : B : 2.0 commons-logging commons-logging 1.0.1 commons-logging commons-logging 1.1.1 commons-logging commons-logging 1.1.1 D : D : 1.0 commons-logging commons-logging 1.0.4 Which commons-logging? ?? ? ?
  • 41. A : A : 1.0 B : B : 1.0C : C : 1.0 B : B : 2.0 commons-logging commons-logging 1.0.1 commons-logging commons-logging 1.1.1 commons-logging commons-logging 1.1.1 D : D : 1.0 commons-logging commons-logging 1.0.4 The Sequential first at the same distance…
  • 42. The Final Graph… A : A : 1.0 B : B : 1.0C : C : 1.0 commons-logging commons-logging 1.0.4 D : D : 1.0
  • 43. Question: Project A will work in the end 
 OR not? A : A : 1.0 B : B : 1.0C : C : 1.0 commons-logging commons-logging 1.0.4 D : D : 1.0
  • 46. Aggregation ProjectA ProjectB ProjectC <<depends>> <<depends>> root $ cd ProjectC projectC $ mvn compile projectC $ cd .. root $ cd ProjectB projectB $ mvn compile projectB $ cd .. root $ cd ProjectA projectA $ mvn compile } 8 lines !!!
  • 47. Aggregation modulesapp ProjectA ProjectB ProjectC <<module>> <<module>> <<module>> root $ cd modulesapp modulesapp $ mvn compile modulesapp: <project> <modelVersion>4.0.0</modelVersion> <groupId>tr.org.bimo</groupId> <artifactId>modulesapp</artifactId> <packaging>pom</packaging> <version>1.0</version> <name>modulesapp</name> <modules> <module>projectA</module> <module>projectB</module> <module>projectC</module> </modules> </project>
  • 48. Question here is: With mvn compile which module will compile first? <modules> <module>projectA</module> <module>projectB</module> <module>projectC</module> </modules>
  • 49. Repositories • To manage build artefacts and dependencies • local or remote repositories • Can store jar, war, ear, ejb, rar .... • Maven looks to at least 2 repository if none specified 
 - local one (under user home)
 - http://repo.maven.apache.org/maven2 
 (defined in uber-pom) • Release & Snapshot repositories
  • 50. Repositories <repository> <id>jboss-repo</id> <name>The Release JBoss maven repo</name> <url>http://repository.jboss.org/maven2</url> <releases> <enabled>true</enabled> </releases> </repository> <repository> <id>jboss-snapshot-repo</id> <name>The Snapshot JBoss maven repo</name> <url>http://snapshots.jboss.org/maven2</url> <snapshots> <enabled>true</enabled> </snapshots> </repository>
  • 51. Plugins • Plugin-oriented Architecture
 plugin for even compiling the code.. • A maven artefact w/ descriptor (plugin.xml) and one or more MOJOs • A MOJO is a Maven plain Old Java Object. Each mojo is an executable goal in Maven, and a plugin is a distribution of one or more related MOJOs. • In short, a MOJO is a maven goal, to extend functionality not already found in Maven. • Plexus as its IoC. (Guice also introduced with version 3.x)
 Why not Spring? • List of plugins supported by Maven Project.
 https://maven.apache.org/plugins
  • 52. Plugin Development <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/ XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/ maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>tr.org.bimo</groupId> <artifactId>hello-maven-plugin</artifactId> <version>1.0-SNAPSHOT</version> <packaging>maven-plugin</packaging> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-plugin-plugin</artifactId> <version>3.2</version> <configuration> <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> </configuration> <executions> <execution> <id>mojo-descriptor</id> <goals> <goal>descriptor</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
  • 54. Plugin Development Mojo Code import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; @Mojo( name = "sayhi") public class GreetingMojo extends AbstractMojo { public void execute() throws MojoExecutionException { getLog().info( "Hello world." ); } }
  • 56. What we did w/ plugins in PrimeFaces • Component Class • Tag Handler Class • Declare Component,Tag, Renderer classes in faces-config.xml • Declare facelet tag definition • Declare tld tag definition • maven-jsf-plugin • plugin available @ 
 http://repository.primefaces.org/org/primefaces/maven-jsf-plugin
  • 57. settings.xml • Maven provides 2 settings file, • Local settings.xml at %USER_HOME%/.m2/settings.xml • Global settings.xml at %M2_HOME%/conf/settings.xml • These files are not bundled with Maven project and don’t get distributed. • If both files exist, their contents get merged. • Local settings.xml overrides the global one.
  • 58. And not to forget that… Maven is our precious…