cvwiki

Maven Wiki

Apr 27, 2022

# Maven Resources

# Maven Commands

1
mvn dependency:tree

# Maven Build Lifecycle

# Clean

# Verify

mvn verify performs any integration tests that maven finds in the project.

# Install

# Package

# Managing Parent POM and Child POMs

To match a parent POM, Maven uses two rules:

  1. There is a pom file in project’s root directory or in given relative path.
  2. Reference from child POM file contains the same coordinates as stated in the parent POM file.

Maven parent pom can contain almost everything and those can be inherited into child pom files e.g

# Example Parent POM

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<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.xsdr">
 <modelVersion>4.0.0</modelVersion>
					 
 <groupId>com.howtodoinjava.demo</groupId>
 <artifactId>MavenExamples</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>pom</packaging>
					 
 <name>MavenExamples Parent</name>
 <url>http://maven.apache.org/</url>
					 
 <properties>
	 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	 <junit.version>3.8.1</junit.version>
	 <spring.version>4.3.5.RELEASE</spring.version>
 </properties>
					 
 <dependencies>
					 
 <dependency>
	 <groupId>junit</groupId>
	 <artifactId>junit</artifactId>
	 <version>${junit.version}</version>
	 <scope>test</scope>
 </dependency>
					 
 <dependency>
	 <groupId>org.springframework</groupId>
	 <artifactId>spring-core</artifactId>
	 <version>${spring.version}</version>
 </dependency>
					 
 </dependencies>
</project>

# Example Child POM

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<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.xsdr">
 
<!--The identifier of the parent POM-->
 <parent>
	 <groupId>com.howtodoinjava.demo</groupId>
	 <artifactId>MavenExamples</artifactId>
	 <version>0.0.1-SNAPSHOT</version>
</parent>
	
 <modelVersion>4.0.0</modelVersion>
 <artifactId>MavenExamples</artifactId>
 <name>MavenExamples Child POM</name>
 <packaging>jar</packaging>
					 
 <dependencies>
	 <dependency>
		 <groupId>org.springframework</groupId>
		 <artifactId>spring-security</artifactId>
		 <version>${spring.version}</version>
	 </dependency>
 </dependencies>
</project>

# Maven Snapshots

A snapshot version in Maven is one that has not been released.

The idea is that before a 1.0 release (or any other release) is done, there exists a 1.0-SNAPSHOT. That version is what might become 1.0. It’s basically “1.0 under development”.

The difference between a “real” version and a snapshot version is that snapshots might get updates. That means that downloading 1.0-SNAPSHOT today might give a different file than downloading it yesterday or tomorrow.

Usually, snapshot dependencies should only exist during development and no released version (i.e. no non-snapshot) should have a dependency on a snapshot version.

The snapshot is not necessarily more stable: it is just the latest build. The snapshot precedes the actual release, it does not come after it.