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.
Prerequisites
Section titled “Prerequisites”- Java 17 or newer
- Maven 3.6.0 or newer
Install Nx
Section titled “Install Nx”You can install Nx globally. Depending on your package manager, use one of the following commands:
brew install nxchoco install nxsudo add-apt-repository ppa:nrwl/nxsudo apt updatesudo apt install nxnpm install --global nx@latestYou can use
pnpm,yarn, orbunif you prefer as well.
Add Nx to a Maven Workspace
Section titled “Add Nx to a Maven Workspace”If you are in a Maven workspace without Nx, start here. This command adds Nx and configures @nx/maven:
nx initVerify that Nx discovered your Maven modules:
nx show projectsnx show project my-app --webReplace my-app with a module name from your workspace.
Add @nx/maven to an Existing Nx Workspace
Section titled “Add @nx/maven to an Existing Nx Workspace”If you already have an Nx workspace, add the Maven plugin:
nx add @nx/mavenVerify the plugin is active by inspecting a module:
nx show project my-app --webReplace my-app with a module name from your workspace.
Local Development
Section titled “Local Development”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:
nx compile my-modulenx test my-modulenx package my-modulenx verify my-moduleIf you configure a targetNamePrefix (for example mvn-), use the prefixed targets instead:
nx mvn-test my-moduleConfiguration
Section titled “Configuration”How @nx/maven Infers Tasks
Section titled “How @nx/maven Infers Tasks”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:
nx show project my-module --web@nx/maven Configuration
Section titled “@nx/maven Configuration”Configure the plugin in the plugins array of nx.json.
{ "plugins": [ { "plugin": "@nx/maven", "options": { "targetNamePrefix": "mvn-", "verbose": false } } ]}| Option | Type | Default | Description |
|---|---|---|---|
targetNamePrefix | string | undefined | Prefix all inferred Maven targets to avoid name collisions in polyglot workspaces. |
verbose | boolean | false | Enable verbose logging for the Maven analyzer. Also settable via NX_VERBOSE_LOGGING=true. |
Exclude or Include Specific Projects
Section titled “Exclude or Include Specific Projects”Use include/exclude glob patterns to scope the plugin to specific projects:
{ "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.
CI Considerations
Section titled “CI Considerations”Build and test only what changed using the project graph:
nx affected -t test packageConnect Nx Cloud to share cache results and speed up Maven builds in CI:
nx connectBatch Mode
Section titled “Batch Mode”Batch mode runs multiple Maven tasks in a single invocation. Enable it by setting NX_BATCH_MODE=true:
NX_BATCH_MODE=true nx run-many -t build testSee 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.