Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Multi Module Maven Project in VSCode

I am planning to built multi module Maven Java Project as part of creating a mono repo. IntelliJ IDE has an easy way to build Maven Modules inside an existing Maven Project. https://www.codejava.net/ides/intellij/create-multi-module-maven-project-intellij

(e.g. Right-click on the root project, and select New > Module:)

Is there a similar feature in VSCode or a plugin to create module in an existing Maven Project?

I have already installed the "Extension Pack for Java" plugin https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack as well as "Maven for Java" plugin https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven

Interestingly VSCode recognizes modules in a multi-module Maven if you open one with it. It just doesn't have a way of adding new module afaik.

like image 924
pref Avatar asked Oct 27 '25 09:10

pref


1 Answers

After you've created a parent with <packaging>pom<packaging> tag, right-click on plus-sign on "Maven" tab to create a new module, and choose parent's working directory when prompted (In my case "demo"). (Btw, it adds some extra new lines into your parent's pom.xml, so I undo their reformatting, and add <modules><module>Your Name<module><modules> tags manually. Simply copy them before undoing something.)

Maven Tab

To see a new module under "Java Projects", and be able to run, or debug it (debugging in vscode), type "Java: Import Java Projects into Workspace" into "Command Palette" (Cntrl+Shift+P)

In parent's pom.xml should appear modules tag:

  <groupId>com.example</groupId>
  <artifactId>demo</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>
    
  <modules>
    <module>demo-first</module>
  </modules>

In child's pom.xml should be generated these tags:

  <parent>
    <artifactId>demo</artifactId>
    <groupId>com.example</groupId>
    <version>1.0</version>
  </parent>

  <artifactId>demo-first</artifactId>
  <version>1.0</version>
like image 161
Cyrus Avatar answered Oct 28 '25 22:10

Cyrus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!