Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Maven Revisited

No description
by

Anton Weiss

on 21 December 2014

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Maven Revisited

Why another build framework?

Make the build process easy
Provide a uniform build system
Provide quality project information
Provide guidelines for best practices development
Allow transparent migration to new features
Maven Revisited
Maven Revisited

Why another build framework?
Maven Principles
Maven Architecture
Installation & Configuration
POM Explained
Maven Architecture
Based on Plexus IoC container
Maven Core:
Reads projects details
Tracks lifecycle
A few core plugins
Maven Plugins:
All the rest

Maven Principles
Convention Over Configuration

Reuse through plugins

Project model concept
Installation & Configuration
Install from http://maven.apache.org/download.cgi
Edit %USERPROFILE%/.m2/settings.xml
http://books.sonatype.com/mvnref-book/reference/appendix-settings-sect-details.html
Maven Core
• POM Explained
• Project Relationships
• Versions&Properties
• Repositories (Local & Remote)
• Managing Dependencies
• Life-cycle Phases
• Using Profiles
• Packaging types
• Maven Plugins

The super POM :

The simplest POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.att.tlv</groupId>
<artifactId>simplest-project</artifactId>
<version>1</version>
</project>
>
mvn help:effective-pom
Project Relationships
Project Coordinates:
artifactId
groupId
version
classifier

Project Inheritance:
<project>
<parent>
<groupId>com.training.killerapp</groupId>
<artifactId>a-parent</artifactId>
<version>1.0-SNAPSHOT</version>

<relativePath>../a-parent/pom.xml</relativePath>
</parent>

<artifactId>project-a</artifactId>
...
</project>
Inherited:
identifiers (at least one of groupId or artifactId must be overridden.)
dependencies
developers and contributors
plugin lists
reports lists
plugin executions (executions with matching ids are merged)
plugin configuration
Versions&Properties
Versions:
SNAPSHOT vs. Release :

<major version>.<minor version>.<incremental version>-<qualifier>
Example :
<version>0.0.1-SNAPSHOT</version>
Property References:

<build>
<finalName>${project.groupId}-${project.artifactId}</finalName>
</build>
env - ${env.hostname}
project - ${project.groupId}
settings - ${settings.offline}
java System properties : ${java.home}, ${os.name},etc...
custom properties :
<properties>
<foo>bar</foo>
</properties>
Repositories
Local : %USERPROFILE%\.m2\repository
Remote:

<settings ...>
...
<profiles>
<profile>
...
<repositories>
<repository>
<id>nexus_snapshots</id>
<name>ATT Nexus Snapshots</name>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://iltlvora110:8081/nexus/content/repositories/snapshots</url>
<layout>default</layout>
</repository>
</repositories>
Plugin Repositories:
<pluginRepositories>
<pluginRepository> ...
Managing Dependencies
<project>
...
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<
scope>test</scope>
</dependency>...
Dependency Scopes:
compile -
classpath, package
provided -
classpath
runtime -
runtime only
test -
test only
system -
local path
import -
import from POM
Version Ranges :
(, ) Exclusive quantifiers
[, ] Inclusive quantifiers
<version>[3.8,4.0)</version> : 3.8 <= version < 4.0
Managing Dependencies
Dependencies are Transitive
But can be optional:
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>1.4.1</version>

<optional>true</optional>
</dependency>
project
a
> project b > project
c
==> project
a
> project
c
Transitive Dependencies and Scope
Conflict Resolution
Excluding a Transitive Dependency.

<dependency>
<groupId>org.otomato.training/groupId>
<artifactId>project-a</artifactId>
<version>1.0</version>

<exclusions>
<exclusion>
<groupId>org.otomato.training/groupId>
<artifactId>project-b</artifactId>
</exclusion>
</exclusions>
</dependency>
dependencyManagement
element:
define versions in the top-level POM
skip version definition in child POMs
POM Best Practices

grouping POM to define all dependencies
<packaging>pom</packaging>
mvn install
other projects - depend on the grouping POM:
Grouping Dependencies:
<dependency>
<groupId>com.att.uc</groupId>
<artifactId>grouping-deps</artifactId>
<version>1.0</version>

<type>pom</type>
</dependency>
Project Relationships
Multi-module projects:
<modules>
<module>my-backend</module>
<module>my-webapp</module>
</modules>

Top-level POM :
Convenience : one '
mvn package
' for all
Dependency Analysis
mvn dependency:tree
>mvn dependency:tree -Dverbose -Dincludes=commons-collections
[INFO] [dependency:tree]
[INFO] org.apache.maven.plugins:maven-dependency-plugin:maven-plugin:2.0-alpha-5-SNAPSHOT
[INFO] +- org.apache.maven.reporting:maven-reporting-impl:jar:2.0.4:compile
[INFO] | \- commons-validator:commons-validator:jar:1.2.0:compile
[INFO] | \- commons-digester:commons-digester:jar:1.6:compile
[INFO] | \- (commons-collections:commons-collections:jar:
2.1
:compile -
omitted for conflict with 2.0)
[INFO] \- org.apache.maven.doxia:doxia-site-renderer:jar:1.0-alpha-8:compile
[INFO] \- org.codehaus.plexus:plexus-velocity:jar:1.1.3:compile
[INFO] \-
commons-collections:commons-collections:jar:2.0:compile
Nearest-Wins Principle
The Lifecycle
Defines what to do with the project
A sequence of phases
Plugin goals are tied to lifecycle phases
Goal<->Phase tie defined by packaging

clean
: pre-clean, clean, post-clean
default
: validate, ...compile, ...package, ...deploy
site
: pre-site, site, post-site, site-deploy


Standard Lifecycles:
Define custom goal<->phase relationship
<plugin>
<groupId>com.mycompany.example</groupId>
<artifactId>display-maven-plugin</artifactId>
<version>1.0</version>

<executions>
<execution>
<
phase
>process-test-resources</
phase
>
<goals>
<goal>time</goal>
</goals>

</execution>
</executions>
</plugin>
Build Profiles
Enable Build Portability for Different Environments
Profile is :
an alternative set of configuration values which set or override default values.
Specify profile on command line:
mvn <lifecycle phase> -p<ProfileName>
Profile Activation
<profiles>
<profile>
<id>linux</id>
<activation>
<activeByDefault>false</activeByDefault>
<os>
<name>Linux</name>
</os>
<property>
<name>environment</name>
<value>test</value>
</property>
</activation>
Core Plugins
Build plugins - build lifecycle
clean
compiler
deploy
install
jar
war
Reporting plugins - site lifecycle
changes
javadoc
Archetype Plugin:

mvn:archetype generate -DarchetypeGroupId=...
-DarchetypeArtifactId=...
2 More Plugins
Eclipse Plugin:

mvn eclipse:eclipse
project a > (optional) project b
project x >project a
project x > project b
Full transcript