Maven
Maven
Introduction to Maven
Chengyu Sun
California State University, Los Angeles
Build
Preprocessing
Compilation
Postprocessing
Distribution
Deployment
What is Maven?
Mostly used as a build tool for Java
projects
It is more than a build tool
Project Object Model (POM)
Project lifecycles
Dependency management
Plugin framework
It is a project management tool
A Simple Maven Example
pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>edu.calstatela.cs520</groupId>
<artifactId>maven-exmaple</artifactId>
<version>1.0</version>
</project>
Run:
mvn compile
mvn package
pom.xml and modelVersion
pom.xml is a description of the project
modelVersion is the version of the
“grammar” of the description
Maven Coordinates
groupId
Name of the company, organization, team etc.,
usually using the reverse URL naming convention
artifactId
A unique name for the project under groupId
version
packaging, default: jar
classifier
http://maven.apache.org/plugins/index.html
Example of Using a Plugin
<build><plugins><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions><execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<target>1.6</target>
</configuration>
</execution></executions>
</plugin></plugins></build>
About The Plugin Example
A plugin is uniquely identified by its
coordinates just like any other project
Goals are usually associated (i.e.
bound) to a build lifecycle phase
The behavior of a goal can be
customized with additional parameters
in the <configuration> section
Run a Maven Build
mvn <phase>