1 Concept Introduction
All configurations for a project are placed in the POM file: Define the type of project, name, manage dependencies, customize plugin behavior, and so on. For example, you can configure the compiler plugin to use java1.5 to compile.
[HTML]View PlainCopyPrint?
- < Project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/ Xmlschema-instance "
- xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
- < modelversion >4.0.0</modelversion>
- < groupId >com.mycompany.helloworld</groupId>
- < Artifactid >helloworld</artifactid>
- < version >1.0-snapshot</version>
- < Packaging >jar</packaging>
- < name >helloworld</name>
- < URL >http://maven.apache.org</url>
- < Properties >
- < project.build.sourceEncoding > UTF-8</project.build.sourceEncoding>
- </ Properties >
- < Dependencies >
- < Dependency >
- < groupId >junit</groupId>
- < Artifactid >junit</artifactid>
- < version >3.8.1</version>
- < Scope >Test</scope>
- </ Dependency >
- </ Dependencies >
- </ project >
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < Modelversion>4.0.0</modelversion> <groupId>com.mycompany.helloworld</groupId> <artifacti D>helloworld</artifactid> <version>1.0-SNAPSHOT</version> <packaging>jar</packagin g> <name>helloworld</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <d ependencies> <dependency> <groupId>junit</groupId> <artifactid>junit< ;/artifactid> <version>3.8.1</version> <scope>test</scope> </depend Ency> </dependencies> </project>
In POM, Groupid,artifactid, packaging, and version are called Maven coordinates, which uniquely determine a component. With maven coordinates, we can use it to specify other projects, plugins, or parent projects on which our project depends.
Typically, large projects are generally divided into sub-projects. In this case, each subproject will have its own POM file, and then they will have a common parent project. This makes it possible to build all of the child projects as long as the parent project is built. The Pom of the subproject inherits the parent project's POM. In addition, all POM has inherited a super-pom. Super-pom sets some default values, such as the default directory structure mentioned earlier, the default plug-in, and so on, which follows the principle that the Convention is better than the configuration. Such as:
2 inheritance and aggregation of pom files
Inherited
Common configuration-dependencies (including public class libraries, plug-ins, information configurations) are typically put into a pom file for a parent project, and then the Pom file for other projects is inherited by the development. The inherited code is as follows:
It is important to note that the child pom file does not inherit all of its dependencies unconditionally, such as plugins, class libraries, and so on, once it inherits the parent Pom. If the child Pom wants to inherit a plugin from the parent pom, it is only necessary to introduce the GroupID and artifactid information of the plug-in in the parent pom (without having to write other configuration information for the plugin). In this way, a child pom can selectively inherit what it needs.
Polymerization
That is, a large project typically has an empty MAVEN project (only the Pom file, no Java code) as the parent project, and the project's Pom file (in the modules tag) aggregates the pom files for the other subproject, and then builds all the sub-projects as long as the parent project is built.
From for notes (Wiz)
About POM (Project Object Model)