在 Java 项目里“依赖版本怎么选”是个很常见、但也容易踩坑的问题。下面从原则 → 具体做法 → 常见场景给你一个清晰思路。
不要到处写版本号。
<dependencyManagement>platform() / constrained / versions✅ 好处:
只看这几种:
1.2.3(GA / RELEASE)2.0.0❌ 不建议新手用:
SNAPSHOT(不稳定)RC / M1 / Beta(测试版)选依赖前问自己三个问题:
很多大厂都提供 BOM(Bill of Materials)
例如:
✅ BOM 会帮你锁好子依赖版本
首选 Spring Boot 管版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
</parent>
你只需要:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
✅ 不用写版本
✅ 官方帮你测过兼容性
用 dependencyManagement 统一管理
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.17.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
原则:
例如:
跟着数据库版本走
| 数据库 | 驱动 |
|---|---|
| MySQL 8 | mysql-connector-j 8.x |
| PostgreSQL 15 | postgresql 42.7.x |
| Oracle | 官方 ojdbc |
⚠️ 不要乱升级驱动,可能不兼容
mvn dependency:tree
gradle dependencies
看到:
compile vs runtime 不一致就需要 强制版本
你可以直接说:
我用 Java 17 + Spring Boot 3,xxx 依赖选哪个版本?
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。