Build Tools

A build tool, or software utility, is essential in contemporary software development since it automates the transformation of source code into an executable and deployable program.

  • With build automation, steps like code compilation, assessment, dependency management, & packaging improve the efficiency of the entire development process.

  • Build tools improve productivity, consistency, and dependability across projects and growth environments by automating repetitive and error-prone activities.

Maven

Maven is a widely used build automation and project management tool in the Java software development ecosystem.

Lifecycle

Maven defines a standard build lifecycle consisting of phases such as compile, test, package, install, and deploy. These phases facilitate the build process in a standardized way.

Project Object Model (POM)

Maven projects are defined by a Project Object Model (POM) file, usually named pom.xml. This XML file contains project configurations, dependencies, plugins, and other information required for building the project.

Maven Project Structure

my-project
├── src
   ├── main
      ├── java        # Java source code
      ├── resources   # Resources like configuration files
      └── webapp      # Web application resources (for web projects)
   
   ├── test
       ├── java        # Test source code
       └── resources   # Test resources

├── target             # Compiled bytecode and packaged JARs
├── pom.xml            # Project Object Model configuration file
├── .gitignore         # Git ignore file (if using Git)
└── README.md          # Project documentation

Lifecycle Commands

Maven is based around the central concept of a build lifecycle. What this means is that the process for building and distributing a particular artifact (project) is clearly defined.

There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project's web site.

mvn validate

validate the project is correct and all necessary information is available.

mvn compile

compile the source code of the project.

mvn test

test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.

mvn package

take the compiled code and package it in its distributable format, such as a JAR.

mvn verify

run any checks on results of integration tests to ensure quality criteria are met.

mvn install

install the package into the local repository, for use as a dependency in other projects locally.

mvn deploy

done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

Maven Repositories

Maven downloads the required artifacts or dependencies (jar files) and other plugins which are configured as part of any project, there must be a commonplace where all such artifacts are placed. This common shared area is called a Repository.

Last updated