DEV Community

khalil la
khalil la

Posted on • Updated on

Smooth Maven Project Onboarding

Integrating a large Maven project can be a challenging task. In this article, we will explore how to get familiarize with the Project's Structure easily.
For that we will use nx and a nx plugin called nx-maven that makes the integration with maven possible.

Before we start

Before we start, be sure that you have node.js installed in your machine, the current Long Term Support (LTS) version should work perfectly.

Also be sur that you have java installed, I recommend using the java version 17.
No need to install Maven because we will use the maven wrapper in this article.

Project to use

I choose to work with this repo that you can find on GitHub: https://github.com/jmgarridopaz/bluezone. You can watch this Youtube video to know more about the project : https://www.youtube.com/watch?v=tZzfKCt2Ens

It's a maven multi module project with many modules connected to each other.

I believe its a good idea to start with, and see if we can found how the module are connected.

Install Nx

To be able to run the dependency graph from nx, we need to install nx first. So in the root folder tape this command : npx nx@latest init

choose In this directory option :

PS D:\Workspace\Projects\bluezone> npx nx@latest init
? Where should your workspace be created?
In a new folder under this directory
In this directory
Enter fullscreen mode Exit fullscreen mode

Nx will add the following files :

PS D:\Workspace\Projects\bluezone> npx nx@latest init
โˆš Where should your workspace be created? ยท true
Setting Nx up installation in `.nx`. You can run nx commands like: `./nx.bat --help`
CREATE nx.json
UPDATE .gitignore
CREATE .nx/nxw.js
CREATE nx.bat
CREATE nx
PS D:\Workspace\Projects\bluezone> 
Enter fullscreen mode Exit fullscreen mode

Add nx-maven

Open nx.json file and add @nx/devkit and nx-maven plugins. Be sure the use the latest versions.

{
  "tasksRunnerOptions": {
    "default": {
      "runner": "nx/tasks-runners/default",
      "options": {
        "cacheableOperations": []
      }
    }
  },
  "installation": {
    "version": "16.3.2",
    "plugins": {
      "@nx/devkit": "16.3.2",
      "@jnxplus/nx-maven": "0.6.2"
    }
  },
  "plugins": [
    "@jnxplus/nx-maven"
  ]
}
Enter fullscreen mode Exit fullscreen mode

Run nx graph

Now, run nx graph to see the magic happen :

PS D:\Workspace\Projects\bluezone> nx graph

added 28 packages, and audited 152 packages in 9s

21 packages are looking for funding
  run `npm fund` for details

8 moderate severity vulnerabilities

To address issues that do not require attention, run:
  npm audit fix

To address all issues possible (including breaking changes), run:
  npm audit fix --force

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.

 >  NX   Project graph started at http://127.0.0.1:4211/projects
Enter fullscreen mode Exit fullscreen mode

Navigate to the given URL to watch the deps:

By default the deps are not showing, so click on show all projects button on the left to display all.

(I tried to upload a picture but I think is too big.)

Some explanations :

The arrow from project B to project A means :

  • project A is a aggregator for project B : project A reference project B in the modules section.
  • project B extends project A : project B reference project A using the parent tag.
  • Both the above relationships
  • project A is a dependency for project B.

Hope you like this article and give nx-maven a try.
nx-maven can help manage any java/kotlin project inside nx workspace.

Top comments (0)