Use import scope to resolve Maven inheritance (single) issues

Source: Internet
Author: User
Tags inheritance

Test environment Maven 3.3.9

Presumably everyone in the Springboot application, will have the following code:

[HTML] view plain copy <parent> <groupId>org.springframework.boot</groupId> < ;artifactid>spring-boot-starter-parent</artifactid> <version>1.3.3.RELEASE</version> </ Parent> inherits a parent module and then introduces the corresponding dependency


If said, I do not want to inherit, or I want to inherit multiple, how to do.


We know that Maven inheritance, like Java inheritance, cannot achieve multiple inheritance, and if 10, 20 or more modules inherit from the same module, the dependencymanagement of this parent module will contain a lot of dependencies as we have done before. If you want to classify these dependencies for clearer management, it is impossible, and the import scope dependency can solve this problem. You can put dependencymanagement into a separate pom that is dedicated to managing dependencies, and then you can introduce dependencymanagement by importing a scope dependency in a module that needs to use dependencies. For example, you can write a pom that is used for dependency management:

[HTML]  View Plain  copy   <project>       <modelversion>4.0.0 </modelVersion>       <groupId>com.test.sample</groupId>        <artifactId>base-parent1</artifactId>        <packaging>pom</packaging>       <version>1.0.0-snapshot </version>       <dependencyManagement>            <dependencies>                <dependency>                    <groupId>junit</groupId>                    <artifactid>junit</ Artifactid>                    <version>4.8.2</version>                </dependency>                <dependency>                    <groupId>log4j</groupId>                    <artifactid>

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.