Inheritance and aggregation between projects in Maven

Source: Internet
Author: User

1. Inheritance

Why ① need to inherit.

We know that the dependency transitivity between MAVEN projects is actually the transitivity of dependency between jar packages and war packages, but it must be compile-scoped dependencies that are transitive in order to manage a dependent version on a consistent basis. Depending on the test scope, which exists only in a single project, depending on the version of each project may be different and prone to problems, the problem of the unified version of the test scope depends on the transitive nature of dependencies that cannot be solved. So we use the concept of inheritance to solve.

② How to implement inheritance

Inheritance, as the name suggests, there is a parent-child relationship. We need to define a parent project that manages some of the test scope dependencies uniformly, and the way it is packaged is POM. Declare the dependent coordinates of the test range in its pom file. Then in the subproject the first declaration of the parent project coordinates in the form of <parent> coordinates </parent> declares the dependent coordinates of the test range, and also declares the dependent coordinates of the test scope in the subproject. However, it is important to note that the version number in the coordinates must be removed before you can complete the unified management test range-dependent version.

2. Polymerization

Why ① Need aggregation

We will eventually talk about each MAVEN project installed into the warehouse, but because of the inheritance relationship makes it necessary to install the parent project before you can install the subproject, or it will be an error. and must be one by one install. So can there be a better way to complete a one-click installation. The polymerization project can be completed.

② How to achieve aggregation

We first define a package for the POM project as an aggregation project, and in which a MAVEN project is aggregated in the form of a <models><model></model></models> tag , it does not have to be in the order of the model, it automatically recognizes the parent project to complete the installation first. Then only then will this polymerization engineering install then the aggregation in the project can be smooth install.

It should be noted that in the actual project development project, we can use the same POM packaging project to act as a parent engineering and polymerization project. The effect is that the Pom.xml file contains a test-scoped dependency and a models tag that aggregates each MAVEN 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.