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:
- Cache task results
- Distribute task execution
- Run only tasks affected by a PR
- Interactively explore your workspace
Setup @nx/maven
Section titled “Setup @nx/maven”Install Nx
Section titled “Install Nx”You can install Nx globally. Depending on your package manager, use one of the following commands:
npm add --global nx@latestbrew install nxchoco install nxsudo add-apt-repository ppa:nrwl/nxsudo apt updatesudo apt install nxAdd Nx to a Maven Workspace
Section titled “Add Nx to a Maven Workspace”In any Maven workspace, run the following command to add Nx and the @nx/maven plugin:
nx initThen, you can run Maven tasks using Nx. For example:
nx build <your maven module>How @nx/maven Infers Tasks
Section titled “How @nx/maven Infers Tasks”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.
View Inferred Tasks
Section titled “View Inferred Tasks”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.
Setting Up @nx/maven in a Nx Workspace
Section titled “Setting Up @nx/maven in a Nx Workspace”In any Nx workspace, you can install @nx/maven by running the following command:
nx add @nx/maven@nx/maven Configuration
Section titled “@nx/maven Configuration”The @nx/maven is configured in the plugins array in 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.