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:
- 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@latest
brew install nx
choco install nx
sudo add-apt-repository ppa:nrwl/nxsudo apt updatesudo apt install nx
Add 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 init
Then, 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
.