Skip to content

调整依赖版本

最后更新: 21 天前

有一些同学在项目开发时,遇到了一些依赖版本的限制,想要升级或降级版本。但在框架里找了半天,也没有找到在哪里进行更改。

这是因为 ContiNew Admin 框架目前的外部依赖主要是在 ContiNew Starter 的 continew-starter-dependencies 模块中进行的版本锁定。(如果刚上手还不知道 ContiNew Admin 和 ContiNew Starter 的关系,请点击查看

下方是 ContiNew Starter v2.13.0 版本的依赖版本锁定,不同 Starter 版本锁定的依赖版本可自行前往 ContiNew Starter 的 continew-starter-dependencies 模块查看。

xml
<spring-boot.version>3.3.12</spring-boot.version>
<spring-cloud.version>2023.0.5</spring-cloud.version>
<redisson.version>3.49.0</redisson.version>
<jetcache.version>2.7.8</jetcache.version>
<cosid.version>2.13.0</cosid.version>
<sa-token.version>1.44.0</sa-token.version>
<just-auth.version>1.16.7</just-auth.version>
<mybatis-plus.version>3.5.12</mybatis-plus.version>
<mybatis-flex.version>1.10.9</mybatis-flex.version>
<dynamic-datasource.version>4.3.1</dynamic-datasource.version>
<p6spy.version>3.9.1</p6spy.version>
<snail-job.version>1.5.0</snail-job.version>
<sms4j.version>3.3.5</sms4j.version>
<aj-captcha.version>1.4.0</aj-captcha.version>
<easy-captcha.version>1.6.2</easy-captcha.version>
<nashorn.version>15.6</nashorn.version>
<fastexcel.version>1.2.0</fastexcel.version>
<poi.version>5.4.1</poi.version>
<x-file-storage.version>2.2.1</x-file-storage.version>
<aws-s3-v1.version>1.12.783</aws-s3-v1.version>
<aws-sdk.version>2.31.63</aws-sdk.version>
<aws-crt.version>0.38.5</aws-crt.version>
<thumbnails.version>0.4.20</thumbnails.version>
<graceful-response.version>5.0.5-boot3</graceful-response.version>
<spel-validator.version>0.5.0-beta</spel-validator.version>
<crane4j.version>2.9.0</crane4j.version>
<knife4j.version>4.5.0</knife4j.version>
<tlog.version>1.5.2</tlog.version>
<truelicense.version>1.33</truelicense.version>
<zip4j.version>2.11.5</zip4j.version>
<okhttp.version>4.12.0</okhttp.version>
<ttl.version>2.14.5</ttl.version>
<ip2region.version>3.3.6</ip2region.version>
<hutool.version>5.8.38</hutool.version>
<snakeyaml.version>2.4</snakeyaml.version>
<!-- 解决部分传递依赖漏洞问题 -->
<commons-beanutils.version>1.11.0</commons-beanutils.version>
<commons-io.version>2.17.0</commons-io.version>
<commons-compress.version>1.26.0</commons-compress.version>
<!-- Maven Plugin Versions -->
<flatten.version>1.7.0</flatten.version>
<spotless.version>2.44.3</spotless.version>
<sonar.version>3.11.0.3922</sonar.version>

理论上,我们不推荐修改 ContiNew Starter 中锁定的依赖版本,原因与 Spring Boot Starter 的作用相同,即进行依赖版本的集中管理,以避免版本冲突。如果你自己做了版本调整,很难说会不会出现版本冲突情况。

但如果你实在等不及 ContiNew Starter 升级或有特殊需求,那么你可以通过下面的方式来调整框架依赖版本。

方式一(简单)

如果你是通过 parent 方式引入的 ContiNew Starter。(ContiNew Admin 默认就是此种引入方式)

xml
<!--
    下方 parent 为 ContiNew Starter(Continue New Starter)。
    ContiNew Starter 基于"约定优于配置"的理念,
    再次精简常规配置,提供一个更为完整的配置解决方案,帮助开发人员更加快速的集成常用第三方库或工具到 Spring Boot Web 应用程序中。
    ContiNew Starter 包含了一系列经过企业实践优化的依赖包(如 MyBatis-Plus、SaToken),
    可轻松集成到应用中,为开发人员减少手动引入依赖及配置的麻烦,为 Spring Boot Web 项目的灵活快速构建提供支持。
-->
<parent>
    <groupId>top.continew.starter</groupId>
    <artifactId>continew-starter</artifactId>
    <version>最新版本</version>
</parent>

那么,你可以利用 Maven 的继承特性,通过在 pom.xml 中覆盖 properties 中的依赖版本变量来调整依赖版本。

例如:要调整 Spring Boot 的版本为 3.4.7,则需要在 pom.xml 中添加如下内容。

xml
<properties>
    <spring-boot.version>3.4.7</spring-boot.version>
</properties>

请注意你要覆盖的变量必须和 ContiNew Starter continew-starter-dependencies 模块中定义的依赖版本变量一致。

方式二

Maven 依赖原则:路径最近者优先、第一声明者优先。基于此依赖原则,你可以在 pom.xml 中直接通过 dependencyManagement 来管理框架的依赖版本。