Skip to content

Apache Maven is a build tool for Java projects that uses a project object model (POM) to manage builds.

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.

  • Java 17 or newer
  • Maven 3.6.0 or newer

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.

Build and test only what changed using the project graph:

Terminal window
nx affected -t test package

Connect Nx Cloud to share cache results and speed up Maven builds in CI:

Terminal window
nx connect

Batch mode runs multiple Maven tasks in a single invocation. Enable it by setting NX_BATCH_MODE=true:

Terminal window
NX_BATCH_MODE=true nx run-many -t build test

See Set Up CI for a complete configuration guide.

If you use Maven profiles or parallel builds in CI, define them in .mvn/maven.config (for example -Pci or -T1C) so Nx runs the same settings consistently.