apache maven for softserve it academy
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/1.jpg)
Apache Maven
Volodymyr Ostapiv2014
![Page 2: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/2.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/3.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/4.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/5.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/6.jpg)
Get it!
![Page 7: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/7.jpg)
Configure
%MAVEN_HOME%\conf\settings.xml
/usr/local/maven/conf/settings.xml
UserProfile\.m2\
~/.m2/
![Page 8: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/8.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/9.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/10.jpg)
Maven + IDE
mvn idea:idea mvn eclipse:eclipse
Generate project files for the most popular IDEs
![Page 11: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/11.jpg)
Path Conventions
![Page 12: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/12.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/13.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/14.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/15.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/16.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/17.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/18.jpg)
Exclusions
<exclusions><exclusion>
<groupId>org.softserve.sse</groupId><artifactId>softserve-sse</artifactId>
</exclusion></exclusions>
![Page 19: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/19.jpg)
Profiles
<profile><id>default</id><activation>
<activeByDefault>true</activeByDefault></activation>
</profile>
(mvn install -Pprofilename)
![Page 20: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/20.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/21.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/22.jpg)
Plugins
Here real magic starts
![Page 23: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/23.jpg)
maven-surefire-plugin
surefire:test
![Page 24: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/24.jpg)
jetty-maven-plugin
mvn jetty:run
![Page 25: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/25.jpg)
tomcat-maven-plugin
mvn tomcat:run
![Page 26: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/26.jpg)
maven-antrun-plugin
mvn antrun:run
![Page 27: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/27.jpg)
maven-compiler-plugin
mvn compiler:compile mvn compiler:testCompile
![Page 28: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/28.jpg)
maven-assembly-plugin
mvn assembly:single
![Page 29: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/29.jpg)
maven-shade-plugin
mvn shade:shade
![Page 30: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/30.jpg)
maven-dependency-plugin
mvn dependency:analyzemvn dependency:tree
![Page 31: Apache Maven for SoftServe IT Academy](https://reader035.vdocuments.us/reader035/viewer/2022062307/5552f6beb4c90587048b4e60/html5/thumbnails/31.jpg)
That’s all