📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
1. Create Maven Projects
Create a Java project
mvn archetype:generate
-DgroupId=org.yourcompany.project
-DartifactId=application
Create a web project
mvn archetype:generate
-DgroupId=org.yourcompany.project
-DartifactId=application
-DarchetypeArtifactId=maven-archetype-webapp
Create archetype from an existing project
mvn archetype:create-from-project
2. Main phases
- clean — delete target directory
- validate — validate, if the project is correct
- compile — compile source code, classes stored in target/classes
- test — run tests
- package — take the compiled code and package it in its distributable format, e.g. JAR, WAR
- verify — run any checks to verify the package is valid and meets quality criteria
- install — install the package into the local repository
- deploy — copies the final package to the remote repository
3. Maven phase commands(Project Build Commands)
mvn clean
mvn validate
mvn compile
mvn test
mvn package
mvn verify
mvn install
mvn deploy
Skip running tests
mvn install -DskipTests=true
mvn install -Dmaven.test.skip=true
4. Project Site Generation
mvn site:site
mvn test site:site
mvn verify site:site
5. Code quality analysis
mvn clean install -DskipTests=true
mvn sonar:sonar
6. Code coverage reporting
It is much more feasible to generate code coverage reports directly from IDE than from Maven. Write test, write code, run coverage for separated test, and check that all important branches are covered.
mvn clover2:setup test clover2:aggregate clover2:clover
mvn clover2:setup verify clover2:aggregate clover2:clover
7. Dependency Management
mvn versions:display-dependency-updates
mvn versions:display-plugin-updates
mvn versions:display-property-updates
mvn dependency:tree
mvn dependency:analyze
8. Getting Help
mvn help:effective-settings
mvn help:effective-pom
settings.xml
and POMs hierarchy):mvn help:active-profiles
m-compiler-p
in the example below):mvn compiler:help
compile
in m-compiler-p
in the example below):mvn compiler:help -Dgoal=compile -Ddetail
- mvn help:describe describes the attributes of a plugin
- mvn help:effective-pom displays the effective POM as an XML for the current build, with the active profiles factored in. Dependency plugin — provides the capability to manipulate artifacts.
- mvn dependency:analyze analyzes the dependencies of this project
- mvn dependency:tree prints a tree of dependencies Compiler plugin — compiles your java code. Set language level with the following configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</
artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
Learn maven here at Apache Maven Tutorial
Comments
Post a Comment
Leave Comment