1

I am planning to built multi module Maven Java Project as part of creating a mono repo. InteliJ 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.

pref
  • 1,651
  • 14
  • 24

3 Answers3

1

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>
Cyrus Ware
  • 11
  • 2
  • I'm not sure about " right-click on plus-sign on "Maven" tab to create a new module " can you add an image? – pref Aug 15 '22 at 22:24
  • I don't see any options when right-clicking the plus sign on the Maven tab. Do you have some extension installed that adds this functionality? – Jeff M Aug 21 '22 at 02:23
  • I see it now. thanks. I think it is part of "Extension Pack for Java". It is not as intuitive, since it doesn't say create module, it say create maven project but if you choose the target inside another maven project then it will added to POM of that parent project – pref Dec 21 '22 at 17:49
0

Of course yes. You can creat the Multi-Module Maven project according to the first four steps in the article.

And right-click your root project and choose "install".

enter image description here

MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13
  • Which article are you referring ? – pref Jun 13 '22 at 18:20
  • @pref The first link cited in your issue. – MingJie-MSFT Jun 14 '22 at 01:06
  • right. that's Intellij. but I'm looking for something similar in VSCode if exists. – pref Jun 14 '22 at 18:08
  • @pref I mean, the first few steps of creating Maven projects in vscode are the same as those in the article. There should be no need to specify how to create parent and child projects in vscode. Finally, click Install – MingJie-MSFT Jun 15 '22 at 01:08
  • The issue is that, in intellij you have a UI to create module Right-click on the root project, and select New > Module: but I don't see that in VSCode. I rephrased my original post to better show my question. – pref Jul 05 '22 at 17:43
0

I know this is a late response but I encountered this problem in my project aswell and it may help someone. My fastest solution is to prepare the parent module with

<packaging>pom</packaging>

Then from your command prompt, in your parent module folder you manually create a new maven project

mvn archetype:generate -DgroupId=org.yourcompany -DartifactId=YourChildModule -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

This will be your new child module, hope it helps.