Skip to content

Overview of the Nx Plugin for Maven

Maven is a build automation tool used primarily for Java projects. Maven addresses two aspects of building software: how software is built and its dependencies.

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:

npm add --global nx@latest

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

nx init

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

nx build <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:

nx add @nx/maven

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

nx.json
{
"plugins": [
{
"plugin": "@nx/maven",
"options": {
"testTargetName": "test",
"buildTargetName": "build"
}
}
]
}

Once a Maven configuration file has been identified, the targets are created with the name you specify under testTargetName or buildTargetName in the nx.json plugins array. The default names for the inferred targets are test and build.