Skip to content

Instantly share code, notes, and snippets.

@brijesh-deb
Last active April 23, 2022 06:36
Show Gist options
  • Save brijesh-deb/a28b191f350b63559d6a9fda2869c516 to your computer and use it in GitHub Desktop.
Save brijesh-deb/a28b191f350b63559d6a9fda2869c516 to your computer and use it in GitHub Desktop.
#CheatSheet #Maven

Maven Cheat Sheet

Installation (Windows)

  • Download and unzip maven installable
  • Set System variable JAVA_HOME
  • Set System variable MAVEN_HOME to folder where maven is extracted.
  • Update PATH to include %MAVEN_HOME%\bin
  • Check : mvn --version

Installation (Mac)

  • Download apache-maven-3.6.3-bin.tar.gz in ../Documents/Softwares
  • Tar -xvf apache-maven-3.6.3-bin.tar.gz
  • Vim ~/.bash_profile
  • Add
    • export M2_HOME=[Home_Dir]/Documents/Softwares/apache-maven-3.6.3
    • export PATH=$PATH:$M2_HOME/bin
  • source ~/.bash_profile
  • Check installation: mvn -version
  • Location of repository : [Home_Dir]/.m2/repository

Enable Proxy setting in Maven

  • Update C:\apache-maven-3.1.1\conf\settings.xml or C:\Users\brijesh_deb.m2\settings.xml
  • Sample:
<proxies>
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>brijesh_deb</username>
      <password>XXXXXX</password>
      <host>XX.XX.XX.XX</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
</proxies>
  • Encrypt user password: mvn --emp [password] [copy this encrypted password in settings.xml]

Commands

  • validate: validate the project is correct and all necessary information is available
  • compile: compile the source code of the project
  • test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package: take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test: process and deploy the package if necessary into an environment where integration tests can be run
  • verify: run any checks to verify the package is valid and meets quality criteria
  • install: install the package into the local repository, for use as a dependency in other projects locally
  • deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
  • clean: cleans up artifacts created by prior builds
  • site: generates site documentation for this project
  • spring-boot:run: run a spring boot application
  • mvn install -Dmaven.test.skip=true : Skip test

Toubleshooting

  • If maven dependencies are not properly added in Eclipse project, add them from command prompt
    • go to folder having pom.xml
    • mvn install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment