Heart containing Coding Chica Local Setup

Local Setup – Maven

TIP: References Quick List

Installation:

Understanding:

Often IDEs can build a Java project directly and produce a jar (java archive file) or other Java-based project archives (for example, ejb, war, rar, or ear files). However, the output generated is often based heavily upon the local configuration in that developer’s IDE. It is not reproducible across a team or between local desktops vs. remote build servers.

Instead, a Maven-based build will be used to generate a more easily reproducible build. While there still may be variations between servers / desktops, the amount of variability is drastically reduced. Also, there are a lot of pre-built plugins that you can simply configure to perform the desired actions during the build process.

Lifecycles

There are 3 different lifecycles / flows that Maven uses when building projects.

  • default
  • clean
  • site

When invoking a phase of the lifecycle, you effectively invoke that and all of the steps prior to it. For example, in the default lifecycle, the phase provided on the Maven command line is deploy then it an all 22 prior phases will be invoked.

mvn deploy

Plugin Goals

You can also invoke individual plugins directly – outside of the lifecycle. In this case, only the specified plugin’s goal is executed. For example, the Maven Help Plugin could be invoked like:

# Fully qualified plugin details
mvn org.apache.maven.plugins:maven-help-plugin:3.4.0:effective-pom

# Or with the shorter alias
mvn help:effective-pom

Default Plugin Bindings

When you configure your Maven project, you will specify a packaging type. Depending upon which option you choose, you will also be configuring some default Maven plugins for certain phases of the Maven lifecycle.

Example:

Packaging TypePlugin Tied to the Test Phase
jarorg.apache.maven.plugins:maven-surefire-plugin:3.0.0:test
pomN/A

Folder Structure

Maven expects a very specific project folder structure for each module / sub-project in the build. The basics are:

  • src
    • main
      • java
      • resources
    • test
      • java
      • resources

The main folder contains production-bound source code.
The test folder contains tests to run in either the unit / integration phase of the build.
Within the java folders, java packages and then classes should be defined.
Within the resources folders, non-java supporting files can be found.

Installation

💟 CAUTION: If you don’t have Java installed. Then please stop and first follow:

In order to use Maven locally, you will first install it on your local machine.

To do so, follow the instructions at:

Local Setup – Maven

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.