YouTip LogoYouTip

Maven Pom

POM (Project Object Model) is Maven's core configuration file, which uses XML format and is named pom.xml by default. POM is the basic working unit of a Maven project. It is an XML file that contains basic information about the project, describing how the project is built, declaring project dependencies, etc. When executing a task or goal, Maven looks for the POM in the current directory, obtains the required configuration information, and then executes the goal. The following configurations can be specified in POM: * Project dependencies * Plugins * Execution goals * Project build profile * Project version * Project developer list * Related mailing list information Before creating a POM, we first need to describe the project group (groupId) and the project's unique ID. 4.0.0com.companyname.project-groupproject1.0 All POM files require the project element and three required fields: groupId, artifactId, and version. | Node | Description | | --- | --- | | project | The root tag of the project. | | modelVersion | The model version needs to be set to 4.0. | | groupId | This is the identifier of the project group. It is usually unique within an organization or project. For example, a banking organization com.companyname.project-group owns all banking-related projects. | | artifactId | This is the identifier of the project. It is usually the name of the project. For example, consumer banking. groupId and artifactId together define the artifact's location in the repository. | | version | This is the version number of the project. In the artifact's repository, it is used to distinguish different versions. For example: com.company.bank:consumer-banking:1.0 com.company.bank:consumer-banking:1.1 | **Basic POM File Structure:** ## Example 4.0.0 com.example my-app 1.0.0 jar My Application A demo project https://example.com ... ... ... ... **Project Coordinates (Required):** | Element | Description | Example | | --- | --- | --- | | `modelVersion` | POM model version (fixed `4.0.0`) | `4.0.0` | | `groupId` | Organization/company identifier (reverse domain name) | `com.example` | | `artifactId` | Project name | `my-app` | | `version` | Project version | `1.0.0` | | `packaging` | Packaging type (`jar`/`war`/`pom`) | `jar` | **Metadata (Optional):** | Element | Description | | --- | --- | | `name` | Project name (for display) | | `description` | Project description | | `url` | Project homepage | | `licenses` | License information | | `organization` | Organization information | ## Example My Awesome App A demo project for learning Maven https://github.com/example/my-app ### Dependency Management Dependencies can be defined in the POM file: junit junit 4.12 test | Element | Description | | --- | --- | | `groupId` | Organization identifier of the dependency | | `artifactId` | Project name of the dependency | | `version` | Version of the dependency | | `scope` | Dependency scope (`compile`/`test`/`provided`/`runtime`) | | `optional` | Whether the dependency is optional (default `false`) | ### Plugin Management Plugins during the build process can also be defined in the POM file: org.apache.maven.plugins maven-compiler-plugin 3.8.1 1.8 1.8 **Common Plugins:** * `maven-compiler-plugin`: Specifies Java version * `maven-surefire-plugin`: Controls test execution * `maven-jar-plugin`: Customizes JAR package ### Other Common Elements properties: Defines some property variables in the project. Used to define variables to avoid repetition: 11 UTF-8 Reference in dependencies: ${java.version} repositories: Repository configuration. Specify remote repository: aliyun https://maven.aliyun.com/repository/public dependencyManagement: Used to manage dependency versions, especially in multi-module projects. org.springframework spring-core 5.3.9 profiles: Used to define different build configurations, which can
← Project TemplatesPython Mysql Connector β†’