Dependency management and dependencies in maven

Time:2020-6-9

Maven uses the < dependency Management > element to provide a way to manage dependency version numbers, which is usually seen in the top-level parent POM of a project.

Using the < dependencymanagement > element enables all subprojects to refer to a dependency without explicitly listing the version number. The subproject Maven will go up the parent-child level until it finds a project with the < dependencymanagement > element and uses the version number specified by the same dependency.
For example, in the parent project:

 <dependencyManagement>
        <dependencies>
            <!--mysql-->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.2</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

Add MySQL connector java to subproject without specifying version number, such as:

            <!--mysql-->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>
        </dependencies>

It should be noted that:
1. < dependency Management > only declare dependencies, not import them. Subprojects need to display the dependencies required for declaration
2. If another version dependency is needed for a subproject, you only need to declare the version number of the change dependency in the subproject POM

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]