Skip to content

Overview of the Nx Plugin for Maven

Apache Maven is a build tool for Java projects. Using a project object model (POM), Maven manages a project's compilation, testing, and documentation.

The Nx plugin for Maven registers Maven projects in your Nx workspace. It allows Maven tasks to be run through Nx. Nx effortlessly makes your CI faster.

Nx adds the following features to your workspace:

You can install Nx globally. Depending on your package manager, use one of the following commands:

Terminal window
npm add --global nx@latest

In any Maven workspace, run the following command to add Nx and the @nx/maven plugin:

Terminal window
nx init

After initialization, you can view all Maven projects in your workspace:

Terminal window
nx show projects

Then, you can run Maven tasks using Nx. For example:

Terminal window
nx verify <your maven module>

The @nx/maven plugin automatically detects Maven projects in your workspace by scanning for pom.xml files. It analyzes your Maven build structure to create Nx targets for common Maven lifecycle phases and plugin goals.

To view inferred tasks for a project, open the project details view in Nx Console or run nx show project my-project in the command line.

In any Nx workspace, you can install @nx/maven by running the following command:

Terminal window
nx add @nx/maven

The @nx/maven is configured in the plugins array in nx.json.

nx.json
{
"plugins": ["@nx/maven"]
}

Once the plugin has been added, @nx/maven will automatically retrieve information about projects from Maven and create targets for each phase, goal, and some additional targets for CI.