Java maven

From wikinotes

A build system for java.

  • convention over configuration
  • host/integrate with personal package repos
  • manage tests/releases

Documentation

official documentation http://maven.apache.org/
maven 5 minute guide http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

Install

sudo pacman -S maven

Usage

QuickStart

export JAVA_HOME=/usr/lib/jvm/default   # which JDK version should be used?
mvn package                             # build jar from source
java -jar target/package.jar            # run compiled src

Goals

Maven is composed of goals. You run goals by passing them on the commandline (like a makefile targets). You can also build your own goals.

common goals

# run tests
mvn test
mvn test -Dtest=AppTest           # run specific module
mvn test '-Dtest=*Test'           # match modules
mvn test '-Dtest=*#test_*_equal'  # match methods

# compile/run
mvn \
    compile \
    exec:java -Dexec.mainClass=com.example.pkg.App

# create jar
mvn package

overview

mvn clean               # delete old builds
mvn compile             # build
mvn test                # run unittests
mvn integration-test    # run integration tests
mvn package             # build jar, run tests
mvn exec:...            # run compiled

mvn install             # install dependencies
mvn validate
mvn deploy

common plugins

mvn test
mvn javadoc:javadoc

Detailed Usage

java maven: projects
java maven: dependencies



Plugins

Maven's behaviour can be extended using plugins.

java maven plugin: junit
java maven plugin: javadoc
java maven plugin: toolchains