MAVEN Basics

Maven Life Cycles

Compile : .java → .class (/target)


Package : .class → .jar (/target/sample-1.0.2-SNAPSHOT.jar) — same as .exe zip

Install : .jar → copies in local mvn repository ( local — /.m2/…)

deploy: .jar → push to public server — for other developers

Cash: cash something for other job(stages) to use

cf. How to change Java version
/usr/libexec/java_home -V
export JAVA_HOME=`/usr/libexec/java_home -v <version you want>`
Permanently changing
Add the liner to ~/.bash_profile(bash) or ~/.zshrc (zsh) — $SHELL

  • /.M2 : Home directory of where the mvn commands are running ~/.m2
    This is where .jar and .class are stored/cached
  • Mvn needs to bring from public repository?

→ done by surefire plugin (default, no need to download or configure)
Results are generated … /target/surefire-reports/TEST-*.xml
Results are .txt & .xml … html (by surefire report plugin)

mvn package -Dmaven.test.skip=true

This will build jar files(.exe) in the /target directory
uses maven-jar-plugin(JAR) or maven-war-plugin(WAR)
Final JAR and WAR file = SNAPSHOT (project-4.2.5-SNAPSHOT)
+ can also skip tests

→ save the war (snapshot) in ‘registry’

ex. in gitlab to use ‘deploy’ stage → save in package registry(snapshot)
>create ci-settings.xml in project directory (with job-token)
>change pom.xml file with the url & project ID
>gitlab-ci.yml file change → mvn deploy -s ci-settings.xml -DskipTests
Refer to this website :

Refer to :
Cash → multiple PATHs ( — /target, — .m2/…) → PATH is what you want to cache …. normally pushes to external repository googleapi something..
Jobs pick up the cash by KEY of cash

Maven Repository

Maven uses 3 repositories

  • Local repository (.m2)
  • Central repository (Maven Central)
  • Remote repository (Nexus, Gitlab)

Sequence >>
1. Search in local repository → .m2
2. Search in Central repository
3. Remote repository

To manually input a local repository (if not default will be $HOME/.m2)
- Change the [maven installation directory]/conf/settings.xml
There is a <localrepository> section → change this!
- Or input by parameter during mvn command execution
→ mvn clean installorwhatever -Dmaven.repo.local=/home/ec2-user/.m2/repository



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store