Essential Maven Commands for Efficient Multi‑Module Projects
This guide compiles the most useful Maven commands and IDE tips for creating, building, packaging, and deploying multi‑module Java projects, covering project structure, command syntax, advanced combinations, and IntelliJ IDEA integrations.
Background
When automating releases with Maven in large, multi‑module projects, knowing the right commands can dramatically improve productivity. This article collects frequently used Maven commands and practical tips.
Maven Common Commands
Project directory layout:
--P (parent pom)
-- A (module common)
-- B (module biz depends on common)
-- C (module web depends on B, indirectly on A)Creating Projects
Create a standard Maven project:
mvn archetype:create -DgroupId=packageName -DartifactId=projectNameCreate a web Maven project:
mvn archetype:create -DgroupId=packageName -DartifactId=webappName -DarchetypeArtifactId=maven-archetype-webappInstall a third‑party JAR to the local repository:
mvn install:install-file -DgroupId=xxx.xx.xxxx -DartifactId=xxx -Dversion=0.0.1 -Dpackaging=jar -Dfile=path/xxx-0.0.1.jarBuild and Package Commands
Compile source code: mvn compile Compile test code: mvn test-compile Run tests: mvn test Package the project: mvn package Clean compiled artifacts: mvn clean Clean and package together: mvn clean package Clean and install to local repo: mvn clean install List resolved dependencies (useful for conflict analysis): mvn dependency:list Deploy to a remote repository:
mvn deployComplex Combined Commands
Force update of snapshots before packaging: mvn clean package -U Skip unit tests during packaging: mvn clean package -Dmaven.test.skip=true Package with a specific profile (e.g., test environment): mvn clean package -P test Build a specific module and its dependencies: mvn clean install -pl C -am -Dmaven.test.skip=true Build only the parent project: mvn clean install -N Build only module A: mvn clean install -pl A -am Build module A and all modules that depend on it: mvn clean install -pl A -amd Deploy a JAR with tests skipped: mvn clean deploy -Dmaven.test.skip=true Specify an alternative settings file: mvn clean package -s settings.xml Show all Maven help options: mvn -help or
mvn -hIDEA Maven Operations
In IntelliJ IDEA you can run Maven commands directly from the built‑in Terminal, which starts in the project root and is faster than the IDE’s automatic dependency resolution.
Alternatively, use the Maven tool window to execute goals by double‑clicking them; the refresh icons update the dependency tree.
Disabling Unit Tests in IDEA
Click the lightning icon to skip tests during a build, or select multiple goals with Alt/Command for batch execution.
Conclusion
The compiled list of Maven commands and IDE tips aims to streamline daily development and CI/CD workflows for multi‑module Java projects. Readers are encouraged to share additional useful commands.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Senior Brother's Insights
A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
