Maven authoritative guide Study Notes (2)

Source: Internet
Author: User

Maven authoritative guide Study Notes (2) posted by Ryan on 2010/05/02 leave
A comment (0) Go
To comments
  1. POM

    1. Pom is a descriptive statement of a Maven project. It is also a "map" that you need to understand when building a Maven project"
    2. We have determined that POM is descriptive and declarative. It does not provide explicit commands as ant or make does. We also note that the concept of POM is not specific to Java.
    3. Super pom: it is part of Maven installation and can be found in the maven-2.0.9-uber.jar file in/usr/local/Maven/lib. If you look at this jar file, you will see a file named pom-4.0.0.xml under the org. Apache. Maven. project package

      1. The default Super pom defines a separate remote Maven repository, which can be configured through a custom settings. XML file to overwrite. note that the default Super pom disables the function of downloading the snapshot component from the central Maven repository.
      2. The default plug-in repository is the central repository. Snapshot is disabled and the update policy is set to "never". This means that MAVEN will never automatically update a plug-in, even if the new version of the plug-in is released.
      3. The build element sets the default values of those directories in the maven standard directory layout.
      4. Starting from Maven 2.0.9, the super pom provides the default version for the core plug-in.
      5. All Maven pom files are inherited from super pom files.
    4. Maven starts with the super pom, uses one or more parent POM to overwrite the default configuration, and uses the POM of the current project to overwrite the previously generated configuration results. Finally, you get a valid pom that is mixed with various pom configurations. If you want to view the project's valid pom, you need to run the objective-Pom target of the maven help plug-in.
    5. Project version

      1. Maven versions include the main version, minor version, incremental version, and limited version.
      2. A qualified version is used to identify milestone builds: alpha and beta releases. A qualified version is isolated from the primary version by a hyphen.
      3. If your version number and format are <main version>. <version>. <incremental version>-<limited version> matches, and it can be correctly compared. This comparison is based on the value of the main version, next version, and incremental version. If it is not standard, strings are used for comparison.
      4. Maven recognizes the number after the specified version as a build version. However, the build version is parsed using strings for comparison. You can use "alpha-02" and "alpha-10" to solve the problem.
      5. If a version contains the string "snapshot", Maven expands the symbol into a date and time value when installing or releasing the component and converts it to UTC (Coordinated Universal Time) (not tried)
      6. Latest refers to the latest release or snapshot version of a specific component, which is recently deployed to a specific repository. Release is the last non-Snapshot version in the repository. if you are in the software development process, you may want to use release or latest. This is very convenient, and you do not need to update your configuration version for each release of a new third-party class library. But when you release software, you should always be sure that your project depends on a specific version.
    6. Attribute reference

      1. A pom can contain a reference to the attribute through a pair of Large arc and the previous dollar sign.
      2. Maven provides three implicit variables for accessing environment variables, pom information, and Maven settings.
        1. Env: ENV. * environment variables such as path and m2_home can be referenced using the Env. * prefix.
        2. Project: You can use the path marked with (.) to reference the POM element value, for example, $ {project. artifactid}
        3. Settings: for example, $ {settings. Offline} references ~ The value of the offline element in the/. m2/settings. xml file
      3. You can also reference system attributes and any custom attribute groups in Maven POM and the profile.
        1. Java System attributes: All attributes that can be accessed through the getproperties () method in Java. Lang. system are exposed as pom attributes.
        2. We can also set our own properties through the properties element in POM. xml or settings. XML, or use the attributes in the file loaded externally.
    7. Project dependency

      1. Dependency Scope

        1. Compile (compilation range). Compile is the default range. If no range is provided, the dependent range is the compilation range. Compilation scope dependencies are available in all classpath, and they will also be packaged
        2. Provided (range provided ). when you only need a class library during compilation and testing, and the class library is provided by the container during running, you need to use the dependencies of the provided scope. the provided scope dependency is available when classpath is compiled (not runtime. They are not passed or packaged.
        3. Runtime (runtime range). runtime depends on the runtime and test system, but is not required during compilation.
        4. Test (test scope). It is not required in general compilation and runtime. They are only available in the test compilation and test run stages.
        5. System (system scope) system scope dependency is similar to provided, but you must explicitly provide a path for the JAR file in the Local System
      2. Optional dependency (not many, not recommended)
      3. Dependency version limit

        1. (,) Does not contain quantifiers
        2. [,] Include quantifiers
        3. Versions before or after a comma are not required. Such vacancies mean positive infinity or negative infinity.
      4. Transmission dependency: the "transmission dependency and range" is a bit difficult to understand.
      5. Conflict Resolution

        1. Exclude a passed dependency
        2. Exclude and replace a passed dependency
      6. Dependency Management

        1. Maven provides you with a way to unify the dependency version number in the dependencymanagement element. The dependencymanagement element in POM. xml allows you to reference a dependency in a sub-project without explicitly listing the version number.
        2. If a sub-project defines a version, it will overwrite the version in the dependencymanagement element of the top-level pom.
        3. Dependency Management in top-level pom differs from defining a dependency in a widely shared parent pom: All dependencies are inherited. If mysql-connector-Java is listed as a dependency in the parent project at the top level, all projects in this level will reference this dependency. To avoid unnecessary dependencies, dependencymanagement allows you to centrally manage dependent versions without adding dependencies that will be inherited by all sub-projects.
      7. Project relationship

        1. You should avoid using artifactid. This will cause problems when parsing a fully qualified name to the sub-module.
        2. Coordinates: groupid, artifactid, and version. There is also the fourth, also the minimum used qualifier: Classifier
        3. Multi-module projects:

          1. Multi-module projects are those that contain a series of modules to be built. The packaging type of a multi-module project is always pom, and few components are generated. A module project only exists to classify many projects together and become a building
        4. Project inheritance:

          1. Maven assumes that the parent Pom is available in the local repository or in the parent directory (../POM. XML) of the current project. If both locations are unavailable, the default behavior can also be overwritten by the relativepath element.
        5. Pom Best Practices

          1. Dependency classification: If you have a set of logically grouped dependencies. You can create a packaging method for the POM project to put these dependencies together. when you add this project as a dependency, do not forget to specify the dependency type as pom (<type> pom </type>)
          2. Multi-module. inheritance. multi-module building is used to aggregate modules into a single building. parent-child relationship is more about processing the definition of a specific project. two examples are introduced, both of which use multi-module and inheritance. The ideas of these two examples are different and should be well studied.

Original article, reprinted Please note: Reprinted from Ryan's
Note

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.