Synopsis

Maven and Gradle are two popular project management and building tools used by many famous biology programs including ImageJ2, picard, and igv. Both tools are highly versatile and are used for numerous applications (Maven examples) outside of biology.

In this post, I provide a succinct introduction to Maven basics using a minimal openJFX project example. This is a rehash of many references, most notably Maven official guide and openJFX official examples. Both references are well-written and should be ideal starting points for more details.

This work is licensed under CC BY-SA 4.0

Basic concepts

unique identifier of a project - coordinates

A Maven project must define its unique identifier that is called the coordinate of the project. The coordinate has the form groupId:artifactId:version. groupId and artifactId together define what the project is working on while version defines when.

project and its build lifecycles/phases/goals

  1. Each Maven project is stored in its root folder with a single project specification file pom.xml. Its file hierarchy then follows the Maven standard directory layout. For example, your main and test source java files will be under src/main/java and src/test/java.
  2. A defined procedure for building a project is called a build lifecycle. The built-in Maven build lifecycles are default, clean, site.
  3. A build lifecycle is defined by an ordered list of steps (i.e., phases). Built-in lifecycles have predefined phases.
  4. A phase in the lifecycle consists of any number of configurable plugin goal(s). A plugin goal is a specific task on the project.
  5. After a successful build, the generated outputs are called artifacts.

adding goals to build phases

There are two major ways of adding specific goals to the build:

  1. Maven has default goal-to-phase bindings to the default lifecycle. Such default binding depends on packaging type of the project specified by POM element <packaging> (default: jar).
  2. The second way is utilizing Mavn Plugins by specifying POM element <plugins>. A plugin is an artifact that defines one or more goals provided to Maven. To specify what goals to run during different phases, <executions> is used. Refer to the following for more details:

An example Maven project from openJFX

First of all, download/clone to get the Maven modular openJFX CommandLine example files.

Next, change into the hellofx directory and see that the pom.xml and src/ hierarchy implies that this is the root folder of the Maven project. src/main/java has a module-info.java which specifies the use of modularity.