Maven
Basic Structure
Tag | Description |
---|---|
<!DOCTYPE html> |
defines the document type |
<html> |
defines the root element of an HTML page |
<head> |
contains metadata and scripts |
<title> |
specifies the title of the document |
<body> |
contains the visible page content |
Build Lifecycle Phases
Lifecycle | Description |
---|---|
clean |
- Remove all files generated by the previous build. |
compile |
- Compile the source code of the project. |
test |
- Run tests using a suitable unit testing framework. |
package |
- Package the compiled code into a distributable format. |
install |
- Install the package into the local repository. |
deploy |
- Copy the final package to the remote repository. |
Maven Commands
Command | Description |
---|---|
mvn clean |
- Clean the project. |
mvn compile |
- Compile the source code. |
mvn test |
- Run tests. |
mvn package |
- Package the project. |
mvn install |
- Install the project to the local repository. |
mvn deploy |
- Deploy the project to a remote repository. |
mvn clean install |
- Clean and install the project. |
mvn clean test |
- Clean and run tests. |
mvn clean package |
- Clean and package the project. |
Project Configuration
Item | Description |
---|---|
pom.xml |
- Project Object Model (POM) configuration file. |
src/ |
- Directory containing source code. |
target/ |
- Directory containing build output. |
src/test/ |
- Directory containing test source code. |
src/main/resources/ |
- Directory containing resources. |
src/main/java/ |
- Directory containing main Java source code. |
Dependency Management
Item | Description |
---|---|
<dependencies> |
- Define project dependencies in the POM file. |
<dependency> |
- Specify a single dependency. |
<groupId> |
- Group or organization that the dependency belongs to. |
<artifactId> |
- Unique identifier for the dependency. |
<version> |
- Version number of the dependency. |
Build Profiles:
Item | Description |
---|---|
<profiles> |
- Define build profiles in the POM file. |
<profile> |
- Specify a single build profile. |
<id> |
- Unique identifier for the profile. |
<activation> |
- Conditions for activating the profile. |
<properties> |
- Define custom properties in the POM file. |
Plugins:
Item | Description |
---|---|
<plugins> |
- Define build plugins in the POM file. |
<plugin> |
- Specify a single build plugin. |
<groupId> |
- Group or organization that the plugin belongs to. |
<artifactId> |
- Unique identifier for the plugin. |
<version> |
- Version number of the plugin. |
<executions> |
- Configure plugin executions. |
<configuration> |
- Provide configuration options for the plugin. |
Repository Configuration:
Item | Description |
---|---|
<repositories> |
- Define project repositories in the POM file. |
<repository> |
- Specify a single repository. |
<id> |
- Unique identifier for the repository. |
<url> |
- URL of the repository. |
Additional Maven Commands:
Command | Description |
---|---|
mvn clean compile |
- Clean and compile the source code. |
mvn clean test |
- Clean and run tests. |
mvn clean package |
- Clean and package the project. |
mvn dependency:tree |
- Display the project's dependency tree. |
mvn help:effective-pom |
- Display the effective POM after inheritance and active profiles. |
Maven Profiles:
Item | Description |
---|---|
mvn clean install -PprofileName |
- Activate a specific profile during the build. |
mvn help:active-profiles |
- Display active profiles during the build. |