apache maven for softserve it academy

31
Apache Maven Volodymyr Ostapiv 2014

Upload: volodymyr-ostapiv

Post on 13-May-2015

1.405 views

Category:

Education


0 download

DESCRIPTION

Presentation about Apache Maven for SoftServe IT Academy http://akceptor.org/yak-ya-potrapyv-u-it-akademiyu-softserve/

TRANSCRIPT

Page 1: Apache Maven for SoftServe IT Academy

Apache Maven

Volodymyr Ostapiv2014

Page 2: Apache Maven for SoftServe IT Academy

Agenda

▪ What is Maven▪ Getting and installing▪ Basics: POM, GAV, Archetype▪ pom.xml contents▪ Some useful plugins

Page 3: Apache Maven for SoftServe IT Academy

What is Maven

▪Maven is a build automation tool used primarily for Java projects.

▪ Maven addresses two aspects of building software:

1. it describes how software is built 2. it describes its dependencies

Page 4: Apache Maven for SoftServe IT Academy

Maven LifeCycle

•Default lifecycle– generate-sources/generate-resources– compile– test–package– integration-test (pre and post)– install–Deploy

•Separate “clean” lifecycle

Page 5: Apache Maven for SoftServe IT Academy

History

–Maven 1 (2003)–Maven 2 (2005)

▪ Not backwards Compatible

–Maven 3 (2010)▪ Same as Maven 2 but more stable and with some additional features

Page 6: Apache Maven for SoftServe IT Academy

Get it!

Page 7: Apache Maven for SoftServe IT Academy

Configure

%MAVEN_HOME%\conf\settings.xml

/usr/local/maven/conf/settings.xml

UserProfile\.m2\

~/.m2/

Page 8: Apache Maven for SoftServe IT Academy

Create simple project

mvn archetype:generate -DgroupId=[myGroup]-DartifactId=[myArtifact] -DarchetypeArtifactId=maven-archetype-archetype

ORmvn archetype:generate

Page 9: Apache Maven for SoftServe IT Academy

Arche-who? O_o

An archetype is defined as an original pattern or model from which all other things of the same kind are made.

Archetype is a Maven project templating toolkit.

Page 10: Apache Maven for SoftServe IT Academy

Maven + IDE

mvn idea:idea mvn eclipse:eclipse

Generate project files for the most popular IDEs

Page 11: Apache Maven for SoftServe IT Academy

Path Conventions

Page 12: Apache Maven for SoftServe IT Academy

Maven Project Object Model (POM)

▪ Describes a project– Name and Version– Artifact Type– Source Code Locations– Dependencies– Plugins– Profiles (Alternate build config.)

▪ Uses XML by default

Page 13: Apache Maven for SoftServe IT Academy

Project Name (GAV)

▪ Maven uniquely identifies a project using:– groupID: project grouping identifier (no

spaces or colons)▪ Usually loosely based on Java package

– artfiactId: name of project (no spaces or colons)

– version: Version of project▪ Format {Major}.{Minor}.{Maintanence}▪ Add ‘-SNAPSHOT ‘ to identify in development

Page 14: Apache Maven for SoftServe IT Academy

Project Name (GAV)

<?xml version="1.0" encoding="UTF-8"?><project> <modelVersion>4.0.0</modelVersion> <groupId>org.lds.training</groupId>

<artifactId>maven-training</artifactId> <version>1.0</version>

<name>Windows 8</name><description>The best OS ever!</description>

<packaging>jar</packaging><properties>

<java.version>1.6</java.version><properties>

</project>

Page 15: Apache Maven for SoftServe IT Academy

Dependencies

<dependencies><dependency>

<groupId>org.slf4j</groupId><artifactId>slf4j-simple</artifactId><version>1.7.5</version><scope>compile</scope>

</dependency><dependencies>

Page 16: Apache Maven for SoftServe IT Academy

Dependency scope

• compile (default)• provided (by JDK or a container at runtime)• runtime (not required for compilation)• test (used only during tests)• system• import (only available in Maven 2.0.9 or later)

Page 17: Apache Maven for SoftServe IT Academy

Properties

<properties><jdk.version>1.6</jdk.version><spring.version>3.1.2.RELEASE</spring.version><spring.batch.version>2.1.8.RELEASE</spring.batch.version>

</properties>

<dependency><groupId>org.springframework.batch</groupId>

<artifactId>spring-batch-infrastructure</artifactId><version>${spring.batch.version}</version>

</dependency>

mvn install -Dmyproperty=my property from command line

Page 18: Apache Maven for SoftServe IT Academy

Exclusions

<exclusions><exclusion>

<groupId>org.softserve.sse</groupId><artifactId>softserve-sse</artifactId>

</exclusion></exclusions>

Page 19: Apache Maven for SoftServe IT Academy

Profiles

<profile><id>default</id><activation>

<activeByDefault>true</activeByDefault></activation>

</profile>

(mvn install -Pprofilename)

Page 20: Apache Maven for SoftServe IT Academy

Profile activationOperating System based:<activation> <os> <family>unix</family> </os></activation><activation>

<os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version>

</os> </activation>

JDK based:<activation>

<jdk>1.4</jdk> </activation><activation>

<jdk>[1.3,1.6)</jdk></activation>

Page 21: Apache Maven for SoftServe IT Academy

Profile activation

System property based:<activation> <property>

<name>environment</name> <value>test</value>

</property> </activation>File system state based:<activation>

<file> <missing>

target/maven/somefile</missing>

</file> </activation>

Page 22: Apache Maven for SoftServe IT Academy

Plugins

Here real magic starts

Page 23: Apache Maven for SoftServe IT Academy

maven-surefire-plugin

surefire:test

Page 24: Apache Maven for SoftServe IT Academy

jetty-maven-plugin

mvn jetty:run

Page 25: Apache Maven for SoftServe IT Academy

tomcat-maven-plugin

mvn tomcat:run

Page 26: Apache Maven for SoftServe IT Academy

maven-antrun-plugin

mvn antrun:run

Page 27: Apache Maven for SoftServe IT Academy

maven-compiler-plugin

mvn compiler:compile mvn compiler:testCompile

Page 28: Apache Maven for SoftServe IT Academy

maven-assembly-plugin

mvn assembly:single

Page 29: Apache Maven for SoftServe IT Academy

maven-shade-plugin

mvn shade:shade

Page 30: Apache Maven for SoftServe IT Academy

maven-dependency-plugin

mvn dependency:analyzemvn dependency:tree

Page 31: Apache Maven for SoftServe IT Academy

That’s all