๐ ๐ผ๐ฑ๐๐น๐ฒ : ๐ฌ๐ฐ : ๐บ๐๐ป ๐ฝ๐ฎ๐ฐ๐ธ๐ฎ๐ด๐ฒ : ๐ง๐ต๐ถ๐ป๐ด๐ ๐ฏ๐ฒ๐ต๐ถ๐ป๐ฑ ๐บ๐๐ป ๐ฝ๐ฎ๐ฐ๐ธ๐ฎ๐ด๐ฒ
” ฬฒ๐ฬฒ๐ฬฒ๐ฬฒโฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ “: Things behind mvn package
Many beginners think Maven is just a command like : mvn package
๐ ๐ฎ๐๐ฒ๐ป ๐ถ๐ ๐ฎ ๐ฏ๐๐ถ๐น๐ฑ ๐ฎ๐๐๐ผ๐บ๐ฎ๐๐ถ๐ผ๐ป ๐๐ผ๐ผ๐น ๐ณ๐ผ๐ฟ ๐๐ฎ๐๐ฎ ๐ฝ๐ฟ๐ผ๐ท๐ฒ๐ฐ๐๐.
It handles:
– Building code
– Managing dependencies
– Automating the build process
In short : ๐ ๐ฎ๐๐ฒ๐ป = ๐๐๐ถ๐น๐ฑ + ๐๐ฒ๐ฝ๐ฒ๐ป๐ฑ๐ฒ๐ป๐ฐ๐ ๐ ๐ฎ๐ป๐ฎ๐ด๐ฒ๐บ๐ฒ๐ป๐ + ๐๐๐๐ผ๐บ๐ฎ๐๐ถ๐ผ๐ป
Instead of manually compiling code, downloading libraries, running tests, and packaging applications, Maven automates everything using a ๐ฏ๐๐ถ๐น๐ฑ ๐น๐ถ๐ณ๐ฒ๐ฐ๐๐ฐ๐น๐ฒ.
๐ช๐ต๐ฎ๐ ๐ถ๐ ๐ ๐ฎ๐๐ฒ๐ป ๐๐ถ๐ณ๐ฒ๐ฐ๐๐ฐ๐น๐ฒ?
A Maven Lifecycle is a predefined sequence of steps used to build and deliver an application. One command triggers multiple phases automatically.
๐๐น๐ข๐ฎ๐ฑ๐ญ๐ฆ : ๐ฎ๐ท๐ฏ ๐ฑ๐ข๐ค๐ฌ๐ข๐จ๐ฆ
๐๐ฉ๐ช๐ด ๐ณ๐ถ๐ฏ๐ด ๐๐ฎ๐น๐ถ๐ฑ๐ฎ๐๐ฒ โ ๐ฐ๐ผ๐บ๐ฝ๐ถ๐น๐ฒ โ ๐๐ฒ๐๐ โ ๐ฝ๐ฎ๐ฐ๐ธ๐ฎ๐ด๐ฒ
๐ช๐ต๐ ๐ ๐ฎ๐๐ฒ๐ป ๐๐ถ๐ณ๐ฒ๐ฐ๐๐ฐ๐น๐ฒ ๐๐
๐ถ๐๐๐
Before Maven:
– Developers compiled code manually
– Dependencies downloaded manually
– Tests executed manually
– Packaging done manually
Problems:
– Inconsistent builds
– Human errors
– โWorks on my machineโ issues
– Dependency conflicts
๐ ๐ฎ๐๐ฒ๐ป ๐ถ๐ป๐๐ฟ๐ผ๐ฑ๐๐ฐ๐ฒ๐ฑ ๐ฎ ๐๐๐ฎ๐ป๐ฑ๐ฎ๐ฟ๐ฑ๐ถ๐๐ฒ๐ฑ ๐ฎ๐๐๐ผ๐บ๐ฎ๐๐ฒ๐ฑ ๐ฏ๐๐ถ๐น๐ฑ ๐ฝ๐ฟ๐ผ๐ฐ๐ฒ๐๐.
Key Outcomes :
- Standardized builds
- Automated workflows
- Repeatable builds
- CI/CD friendly
๐ ๐ฎ๐๐ฒ๐ป ๐๐ฎ๐ ๐ฏ ๐๐ถ๐ณ๐ฒ๐ฐ๐๐ฐ๐น๐ฒ๐
1๏ธโฃ Default Lifecycle : Builds and deploys the application.
2๏ธโฃ Clean Lifecycle : Removes previous build files.
3๏ธโฃ Site Lifecycle : Generates project documentation.
โฬฒ”ฬฒโฬฒ๐ผฬฒ๐ฬฒ๐ฬฒ๐ฬฒโฬฒ๐ณฬฒ๐ฬฒ๐ฬฒ๐พฬฒ๐ฬฒ๐ฬฒโฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒโฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ขฬฒโฬฒ๐ฬฒ๐ฬฒ๐ฬฒโฬฒ๐ฬฒ๐ฬฒ๐ฬฒโฬฒ๐ณฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒโฬฒ๐ปฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ฬฒ๐ขฬฒ๐ฬฒ๐ฬฒ๐ฬฒโฬฒ”ฬฒ
๐๐ฒ๐ณ๐ฎ๐๐น๐ ๐๐ถ๐ณ๐ฒ๐ฐ๐๐ฐ๐น๐ฒ ๐ฃ๐ต๐ฎ๐๐ฒ๐ :Order matters.
1 validate
2 compile
3 test
4 package
5 verify
6 install
7 deploy
” ๐ฅ๐๐ป๐ป๐ถ๐ป๐ด ๐ฎ ๐น๐ฎ๐๐ฒ๐ฟ ๐ฝ๐ต๐ฎ๐๐ฒ ๐ฒ๐ ๐ฒ๐ฐ๐๐๐ฒ๐ ๐ฒ๐๐ฒ๐ฟ๐๐๐ต๐ถ๐ป๐ด ๐ฏ๐ฒ๐ณ๐ผ๐ฟ๐ฒ ๐ถ๐.
Example: mvn deploy
Runs all phases from validate โ deploy. ‘
๐๐บ๐ฝ๐ผ๐ฟ๐๐ฎ๐ป๐ ๐ฃ๐ต๐ฎ๐๐ฒ๐ ๐๐ ๐ฝ๐น๐ฎ๐ถ๐ป๐ฒ๐ฑ
๐ญ ๐๐ฎ๐น๐ถ๐ฑ๐ฎ๐๐ฒ : ๐๐ต๐ฒ๐ฐ๐ธ๐ ๐ฝ๐ฟ๐ผ๐ท๐ฒ๐ฐ๐ ๐๐๐ฟ๐๐ฐ๐๐๐ฟ๐ฒ ๐ฎ๐ป๐ฑ ๐ฝ๐ผ๐บ.๐
๐บ๐น.
Command: mvn validate
๐ฎ ๐ฐ๐ผ๐บ๐ฝ๐ถ๐น๐ฒ : ๐๐ผ๐บ๐ฝ๐ถ๐น๐ฒ๐ ๐๐ผ๐๐ฟ๐ฐ๐ฒ ๐ฐ๐ผ๐ฑ๐ฒ.
.java โ .class
Output : target/classes
Command: mvn compile
๐ฏ ๐๐ฒ๐๐ : ๐ฅ๐๐ป๐ ๐๐ป๐ถ๐ ๐๐ฒ๐๐๐ (๐๐จ๐ป๐ถ๐, ๐ง๐ฒ๐๐๐ก๐).
Command: mvn test
๐ฐ ๐ฝ๐ฎ๐ฐ๐ธ๐ฎ๐ด๐ฒ : ๐๐ฟ๐ฒ๐ฎ๐๐ฒ๐ ๐ฎ๐ฝ๐ฝ๐น๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป ๐ฝ๐ฎ๐ฐ๐ธ๐ฎ๐ด๐ฒ.
Examples:
.jar โ Java / Spring Boot apps
.war โ Web applications
Output example: target/myapp-1.0.jar
Command: mvn package
๐ฑ ๐๐ฒ๐ฟ๐ถ๐ณ๐ : ๐ฅ๐๐ป๐ ๐ฎ๐ฑ๐ฑ๐ถ๐๐ถ๐ผ๐ป๐ฎ๐น ๐ฐ๐ต๐ฒ๐ฐ๐ธ๐ ๐น๐ถ๐ธ๐ฒ ๐ถ๐ป๐๐ฒ๐ด๐ฟ๐ฎ๐๐ถ๐ผ๐ป ๐๐ฒ๐๐๐ ๐ผ๐ฟ ๐พ๐๐ฎ๐น๐ถ๐๐ ๐ฐ๐ต๐ฒ๐ฐ๐ธ๐.
๐ฒ ๐ถ๐ป๐๐๐ฎ๐น๐น : ๐ฆ๐๐ผ๐ฟ๐ฒ๐ ๐๐ต๐ฒ ๐ฏ๐๐ถ๐น๐ ๐ฎ๐ฟ๐๐ถ๐ณ๐ฎ๐ฐ๐ ๐ถ๐ป ๐๐ต๐ฒ ๐น๐ผ๐ฐ๐ฎ๐น ๐ ๐ฎ๐๐ฒ๐ป ๐ฟ๐ฒ๐ฝ๐ผ๐๐ถ๐๐ผ๐ฟ๐.
Location:
~/.m2/repository
Allows other local projects to use it.
Command: mvn install
๐ณ ๐ฑ๐ฒ๐ฝ๐น๐ผ๐ : ๐จ๐ฝ๐น๐ผ๐ฎ๐ฑ๐ ๐๐ต๐ฒ ๐ฎ๐ฟ๐๐ถ๐ณ๐ฎ๐ฐ๐ ๐๐ผ ๐ฎ ๐ฟ๐ฒ๐บ๐ผ๐๐ฒ ๐ฟ๐ฒ๐ฝ๐ผ๐๐ถ๐๐ผ๐ฟ๐.
Common repositories:
– Nexus
– Artifactory
– GitHub Packages
– AWS CodeArtifact
Command: mvn deploy
(Usually executed in CI/CD pipelines.)
๐๐ฒ๐ ๐ฃ๐ผ๐ถ๐ป๐
๐ฅ๐๐ป๐ป๐ถ๐ป๐ด ๐ฎ ๐ ๐ฎ๐๐ฒ๐ป ๐ฐ๐ผ๐บ๐บ๐ฎ๐ป๐ฑ ๐๐ฟ๐ถ๐ด๐ด๐ฒ๐ฟ๐ ๐ฎ๐ป ๐ฎ๐๐๐ผ๐บ๐ฎ๐๐ฒ๐ฑ ๐ฏ๐๐ถ๐น๐ฑ ๐ฝ๐ถ๐ฝ๐ฒ๐น๐ถ๐ป๐ฒ, ๐ป๐ผ๐ ๐ท๐๐๐ ๐ฎ ๐๐ถ๐ป๐ด๐น๐ฒ ๐๐๐ฒ๐ฝ.