当前位置:网站首页>Dependencymanagement and dependencies

Dependencymanagement and dependencies

2022-06-10 23:08:00 Li_ XiaoJin

DependencyManagement and Dependencies

Maven Use dependencyManagement Element to provide a way to manage dependent version numbers .

Usually at the top of an organization or project POM see dependencyManagement Elements .

Use pom.xml Medium dependencyManagement Element allows all to reference a dependency in a subproject without explicitly listing the version amount .

Maven Will go up the father and son level , Until you find someone who has dependencyManagement Elements of the project , And then it will use this dependencyManagement The version number specified in the element .

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

Then you can add... In the sub project mysql-connector You can not specify the version number , for example :

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

The advantage of doing so is : If multiple subprojects refer to the same dependency , You can avoid declaring a version number in each used subproject , So when you want to upgrade or switch to another version , Just update in the top-level parent container , It doesn't need to be modified one by one ; In addition, if a subproject needs another version , Just declare version Can be .

dependencyManagement It's just a statement of dependency , No introduction , So the child project needs to display the required dependencies for the declaration .

If you don't declare dependencies in subprojects , Is not inherited from the parent project ; Only the dependency is written in the subproject , And no specific version was specified , Will inherit the item from the parent project , also version and scope Read from parent pom. If the version number is specified in the subproject , Then you will use the... Specified in the subproject jar edition .

Copyright: use Creative Commons signature 4.0 International license agreement to license Links:https://lixj.fun/archives/dependencymanagement-dependencies

原网站

版权声明
本文为[Li_ XiaoJin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206102147102065.html