What are 3 build lifecylces in mevan ?
In Maven, there are three main build lifecycles that manage the process of building and deploying a project. Each lifecycle consists of a sequence of phases, and these phases define the steps that are executed during the build process.
Here are the three build lifecycles in Maven:
- Clean
- Default
- Site: responsible for generating the project’s site documentation
1. Default Lifecycle:
- The default lifecycle is responsible for the build and deployment of the project. It handles compiling the code, packaging it, running tests, and installing the artifact into the local repository.
- Phases:
validate
: Validates the project’s structure and configuration.compile
: Compiles the project’s source code.test
: Runs the unit tests on the compiled code.package
: Packages the compiled code into a distributable format (e.g., JAR, WAR).verify
: Runs any checks to ensure the quality of the packaged artifact.install
: Installs the artifact in the local Maven repository.deploy
: Deploys the artifact to a remote repository for sharing with other developers.
2. Clean Lifecycle:
- The clean lifecycle is responsible for cleaning up the project. It ensures that the project’s working directory is in a clean state by removing any previously compiled files and artifacts.
- Phases:
pre-clean
: Performs any operations required before cleaning (e.g., backing up files).clean
: Deletes thetarget
directory where the compiled files and packaged artifacts are stored.post-clean
: Performs operations after cleaning (e.g., restoring backed-up files).
3. Site Lifecycle:
- The site lifecycle is responsible for generating the project’s site documentation and reports. It’s used to build project reports such as code coverage, dependency analysis, and javadoc.
- Phases:
pre-site
: Executes actions before generating the site (e.g., setting up configurations).site
: Generates the project’s site documentation.post-site
: Executes actions after generating the site (e.g., sending site reports).site-deploy
: Deploys the generated site to a web server.
Maven Architecture:
POM (Project Object Model): The core of Maven, defined in pom.xml
, contains project details, dependencies, and configurations.
Build Lifecycle: Maven has three built-in lifecycles:
- Clean → Removes previous build artifacts.
- Default → Handles compilation, testing, packaging, and deployment.
- Site → Generates project documentation.
Each lifecycle consists of phases like compile
, test
, package
, install
, and deploy
.
Repositories (Local, Central, Remote): Maven uses repositories to store dependencies:
- Local Repository (
~/.m2/repository
) → Caches downloaded dependencies. - Central Repository (Maven Central) → Official online repository for open-source libraries.
- Remote Repository → Company-specific artifact storage (e.g., Nexus, Artifactory).
Dependencies & Plugins
- Dependencies (e.g., JUnit, Spring Boot) are automatically resolved via repositories.
- Plugins (e.g.,
maven-compiler-plugin
) extend functionality.
Maven Plugins: Used to execute specific tasks (e.g., compiling, testing, packaging).