Maven Wiki
# Maven Resources
- Apache Maven Docs: Maven CLI Options Reference
- Apache Maven Docs: Maven CI Friendly Versions
- Apache Maven Docs: Maven Plugins
# Maven Commands
- To view the versions of every dependency used throughout your maven project:
|
|
# Maven Build Lifecycle
# Clean
clean
is it’s own build lifecycle phase (which can be thought of as an action or task) in Maven.mvn clean install
tells Maven to do theclean
phase in each module before running theinstall
phase for each module.What this does is clear any compiled files you have, making sure that you’re really compiling each module from scratch.
Once we have the database populated in each environment, we should run a build and test stage.
# Verify
mvn verify
performs any integration tests that maven finds in the project.
# Install
mvn install
– install the package into the local repository, for use as a dependency in other projects locally.mvn install
implicitly runsmvn verify
and then copies the resulting artifact into your local maven repository which you usually can find underC:\Users\username\.m2\repository
if you are using windows.
# Package
mvn package
– take the compiled code and package it in its distributable format, such as a JAR, WAR, or Docker image.- Both of
mvn install
andmvn package
will compile your code, clean the/target
folder, and place a new packaged JAR or WAR into that /target folder. The main difference:mvn install
will also install the package into your local maven repository, for use as a dependency in other projects locally.
# Managing Parent POM and Child POMs
To match a parent POM, Maven uses two rules:
- There is a pom file in project’s root directory or in given relative path.
- 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
- Common data – Developers’ names, SCM address, distribution management etc.
- Constants – Such as version numbers
- Common dependencies – Common to all child. It has same effect as writing them several times in individual pom files.
- Properties – For example plugins, declarations, executions and IDs.
- Configurations
- Resources
# Example Parent POM
|
|
# Example Child POM
|
|
# 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.