This project is a Java-only version of DataStructures that uses Maven, a popular build automation tool for Java projects maintained by the Apache Software Foundation. It supercedes Ant, which is also maintained by Apache.
Maven makes the software build lifecycle less error-prone. Dependency management is simplified since it uses the Maven Central Repository, the de facto repository for Java projects, comparable to PyPI for Python projects and npm for JavaScript projects.
A Maven project has at its root folder:
- A
pom.xml
file, which defines dependencies, plugins, etc.- pom stands for Project Object Model
- A
src
folder, which includes source code (inmain/
) and test code (intest/
) - A
target
folder, which includes generated files (compiled code, documentation, coverage reports,.jar
files, etc.)- This folder is excluded from source control
- An optional
README.txt
file explaining the project (this file, which uses Markdown instead)
The pom.xml
file is of paramount importance to a Maven project. Dependencies, which are located under the <dependencies>
element, need the following tags:
- groupId
- artifactId
- version
- scope, which is usually one of: compile, test, runtime
- Choose the right scope depending on how you use the dependency
Maven utilizes plugins to get things done:
- Maven phases are mapped to plugin:goal pairs; e.g.
compile
maps tocompiler:compile
- You can read more here
Maven commands defined by this project:
mvn checkstyle:checkstyle
runs the Checkstyle utilitymvn compile
compiles the source code into thetarget
foldermvn test-compile
runsmvn compile
and compiles the test code into thetarget
folder, but doesn't run unit testsmvn test
runsmvn test-compile
and runs all unit tests, and produces a JaCoCo code coverage reportmvn package
runsmvn test
and if all tests pass, creates a.jar
file of the project in thetarget
foldermvn install
runsmvn package
and installs the created.jar
file in~/.m2/repository/
, which is where all Maven dependencies get installedmvn javadoc:javadoc
generates Javadoc documentation of the source codemvn site
builds a static website for the project, including the Checkstyle and Javadoc pagesmvn clean
deletes thetarget
foldermvn versions:use-latest-releases
updates all dependency version numbers inpom.xml
- Run
mvn dependency:resolve
to install those updated dependencies
- Run
Maven commands can be combined, e.g. mvn clean test
forces a clean test run by deleting the target
folder before running the unit tests.