Skip to content

Apache Maven is a build tool for Java projects that uses a project object model (POM) to manage builds. Nx adds incremental builds, task caching, and the project graph on top of a Maven monorepo, so a multi-module workspace stays fast as it grows.

The @nx/maven plugin registers Maven modules as Nx projects so you can set up Maven with Nx, run daily Maven tasks, configure task inference, and run in CI.

You can use Maven with Nx without the plugin and still get task caching, task orchestration, and the project graph.

DependencySupported Versions
Java>= 17
Maven>= 3.6.0

Using older Java versions is unsupported and may lead to issues. If you need support for an older version, please create an issue on GitHub.

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

Terminal window
brew install nx

If you are in a Maven workspace without Nx, start here. This command adds Nx and configures @nx/maven:

Terminal window
nx init

Verify that Nx discovered your Maven modules:

Terminal window
nx show projects
Terminal window
nx show project my-app --web

Replace my-app with a module name from your workspace.

If you already have an Nx workspace, add the Maven plugin:

Terminal window
nx add @nx/maven

Verify the plugin is active by inspecting a module:

Terminal window
nx show project my-app --web

Replace my-app with a module name from your workspace.

The plugin infers targets from Maven phases and plugin goals defined in your pom.xml files. By default, the target names are the Maven phase names:

Terminal window
nx compile my-module
nx test my-module
nx package my-module
nx verify my-module

If you configure a targetNamePrefix (for example mvn-), use the prefixed targets instead:

Terminal window
nx mvn-test my-module

The plugin scans your workspace for pom.xml files and analyzes the Maven build to create Nx targets for phases and plugin goals. A root pom.xml at the workspace root is required so the analyzer can resolve the Maven project tree.

To view the inferred tasks for a module, open the project details view in Nx Console or run:

Terminal window
nx show project my-module --web

Configure the plugin in the plugins array of nx.json.

nx.json
{
"plugins": [
{
"plugin": "@nx/maven",
"options": {
"targetNamePrefix": "mvn-",
"verbose": false
}
}
]
}
OptionTypeDefaultDescription
targetNamePrefixstringundefinedPrefix all inferred Maven targets to avoid name collisions in polyglot workspaces.
verbosebooleanfalseEnable verbose logging for the Maven analyzer. Also settable via NX_VERBOSE_LOGGING=true.

Use include/exclude glob patterns to scope the plugin to specific projects:

nx.json
{
"plugins": [
{
"plugin": "@nx/maven",
"include": ["apps/**/*"],
"exclude": ["apps/legacy-app/**/*"],
"options": { ... }
}
]
}

There is no per-project disable for @nx/maven. To stop inference entirely, remove @nx/maven from the plugins array in nx.json.

In CI, Nx runs nx affected to rebuild and retest only the projects a change touches, and caches results to skip repeated work.

For a complete pipeline, see Set up CI.