The difference between dependencies and dependencymanagement in maven

Source: Internet
Author: User

Today, when I configured the Sellercenter interface test environment, I found that some dependencies were not quite consistent:

For example, some dependent <scope> is written in a sub-project <dependencies> under the <dependency> tag,

And some of the dependent <scope> is written in <dependencyManagement> in the parent project.

I know the first kind of writing is right, then a way of writing but do not know right, from the online search, did not find a very precise answer, so he verified a.

The verification process to everyone, we can also practiced hand their own.

Three new items are created first, and the parent as a child project, ProjectA, PROJECTB.

In the parent project, a dependency is as follows:

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

There is no dependency in subproject ProjectA, PROJECTB, Run command mvn Help:effective-pom under ProjectA, and you will find the dependency of JUnit 4.8.1 under a.

If I modify the dependencies in the parent project, this is as follows:

<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Subproject ProjectA, PROJECTB below or no dependencies, Run command mvn help:effective-pom under ProjectA, you will find no dependency on JUnit 4.8.1 under a.

If I add a dependency of JUnit under ProjectA:

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>

After running the command mvn Help:effective-pom under ProjectA, you will find a dependency of JUnit 4.8.1 under a, and scope is test.

It is possible to verify that scope is written in the <dependencies> <dependency> in the subproject, or in the <dependencyManagement> in the parent project.

But one thing to note is that the difference between dependencies and dependencymanagement is:

The former, even if the dependency is not written in a subproject, the child project will still inherit the dependency from the parent project.

The latter, if the dependency is not written in a subproject, the dependency is not inherited from the parent project in the subproject, and the item is inherited from the parent project only if the dependency is written in the subproject, and both version and scope are read from the parent POM.

Transferred from: http://blog.sina.com.cn/s/blog_6125fe5d0100zxrz.html

The difference between dependencies and dependencymanagement in maven

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.