MAVEN's Pom.xml file structure build configuration Build

Source: Internet
Author: User
Tags relative xmlns

In Maven's Pom.xml file, the build-related configuration contains two parts, one is <build>, and the other is <reporting>, where we'll just introduce <build>.


1. In the Pom.xml document of Maven, there are two types of <build>:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd" >
  ...
  <!--"Project build" contains elements of the Basebuild set and the build set-->
  <build>...</build>< c5/><profiles>
    <profile>
      <!--"Profile builds" contains elements of the Basebuild set only-->< c8/><build>...</build>
    </profile>
  </profiles>
</project>
Description

A <build> is called a project build, which is a direct child element of <project>. Another <build> is called the profile build, which is the direct child element of <profile>.

The profile build contains the basic build element, and the project build contains two special elements, the various ... Directory> and <extensions>.


2. The basic build element shared by profile and project build

1) Examples are as follows:

<build>
  <defaultGoal>install</defaultGoal>
  <directory>${basedir}/target</ Directory>
  <finalName>${artifactId}-${version}</finalName> ...
</build>
Description: Defaultgoal, execute the build-time default goal or phase, such as Jar:jar or package directory, build the path of the result, the default is ${basedir}/target catalog Finalname, The name of the final result of the build, which may have been changed in other plugin


2) <resources>

Resources are often not code, they do not need to be compiled, but some properties or XML configuration files, which tend to copy the resource files from the source path to the specified target path during the build process.

<resources> give a specific path to each resource in the MAVEN project. Examples are as follows:

Description: Resources,build process involved in the resource file TargetPath, the target path of resource files filtering, whether the construction process to filter resources, default false directory, resource file path, default is located in ${ Basedir}/src/main/resources/directory includes, a set of file name matching pattern, the matching resource file will be built process processing excludes, a set of file name matching pattern, the matching resource file will be ignored by the construction process. Resource files that are matched by both includes and excludes will be ignored. Filters, gives the path to the property file that filters the resource file, which is located in the ${basedir}/src/main/filters/directory by default. A number of key-value pairs are defined in the property file. During the build process, the variable (key) that appears in the resource file is replaced with the value corresponding to that key in the property file. The resource files involved in the Testresources,test process are located in the ${basedir}/src/test/resources/directory by default. The resource files Here are not built into the target artifacts.


3) <plugins>

<plugins> gives the plug-ins used in the build process.


  <build> ...
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        < artifactid>maven-jar-plugin</artifactid>
        <version>2.6</version>
        <extensions >false</extensions>
        <inherited>true</inherited>
        <configuration>
          < classifier>test</classifier>
        </configuration>
        <dependencies>...</ dependencies>
        <executions>...</executions>
      </plugin>
    </plugins>
  </build>

Description

GroupId Artifactid version extensions, whether to load the extension of the plug-in, the default false inherited, and whether the configuration in the configuration of the plug-in can be inherited by (inheriting the other MAVEN project of the Pom). The default true configuration, a special configuration required by the plug-in, can overwrite or merge dependencies between parent-child projects, a dependency class library that is unique to the plug-in, executions, The way in which one of the plug-ins goal (a plug-in may contain multiple goal). A execution has the following settings: ID, unique identification goals, the goal of the plug-in to execute (can have multiple), such as <goal>run</goal> phase, plug-in goal to embed in the MAVEN phase to execute, such as verify inherited, whether the execution can inherit configuration from the quilt project, and the other configuration parameters of the execution


4) <pluginManagement>

The relationship between,<pluginmanagement> and <plugins> in <build> is similar to <dependencyManagement> and < The relationship between the dependencies>. <plugin> is also configured in <pluginManagement>, and its configuration parameters are exactly the same as <plugin> in <plugins>. Only,<pluginmanagement> often appear in the parent project, where the configured <plugin> is often common to subprojects. As long as the plug-in is declared in <plugins> by <plugin>, the plug-in's specific configuration parameters are inherited from the parent project <pluginManagement> configuration of the plug-in, thereby avoiding duplicate configuration in subprojects.


3. Project build-specific; Directory>

is often configured in the parent project for use by all parent-child projects. Examples are as follows:

  <build>
    <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
    < Scriptsourcedirectory>${basedir}/src/main/scripts</scriptsourcedirectory>
    <testSourceDirectory >${basedir}/src/test/java</testSourceDirectory>
    <outputdirectory>${basedir}/target/classes </outputDirectory>
    <testoutputdirectory>${basedir}/target/test-classes</testoutputdirectory > ...
  </build>
</project>

The directory can use an absolute path, as shown in the example. If you use a relative path, all relative paths are in the ${basedir} directory.


4. Project Build-specific <extensions>

<extensions> is an additional tool that can be used to perform the build process and is added to the classpath during the execution of the build.

You can also change the build process by <extensions> activating the plug-in.

Generally, a specific implementation of a general-purpose plug-in is given through <extensions> for the construction process.

Examples of the use of <extensions> are as follows:

  <build> ...
    <extensions>
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
        < artifactid>wagon-ftp</artifactid>
        <version>1.0-alpha-3</version>
      </extension >
    </extensions>
    ...
  </build>
</project>






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.