Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Right now I usually find a pom.xml file on the web that has a pom packaging and copy and paste it to create my parent project. Then I used to run archetype:create inside the parent directory to create sub modules but archetype:create has become deprecated since then.

Any recommendations on how to create new Maven multi-module projects?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
143 views
Welcome To Ask or Share your Answers For Others

1 Answer

The easiest way I've found to do this is to use the pom-root archetype to create the top-level pom and then repeatedly use archetype:generate to create each module individually. This will automatically add the modules to the root pom (aggregator) and set the root pom as the parent pom for each module (edit: apparently some archetypes can have a hard-coded parent, but it works for maven-archetype-quickstart).

Here's the breakdown:

  1. Create the top-level root:

    mvn archetype:generate 
    -DarchetypeGroupId=org.codehaus.mojo.archetypes 
    -DarchetypeArtifactId=pom-root 
    -DarchetypeVersion=RELEASE
    
  2. cd into your newly created root dir.

  3. For each module:

    mvn archetype:generate 
    -DarchetypeGroupId=org.apache.maven.archetypes 
    -DarchetypeArtifactId=maven-archetype-quickstart 
    -DarchetypeVersion=RELEASE
    

Note that -DarchetypeVersion=RELEASE above will automatically use the latest version of the archetype. You may want to add -DgroupId=... to each of those commands to avoid repeating yourself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...