物料清单 (Bill of Materials, BOM) 是 Maven 的标准功能,提供集中化的依赖版本管理。ShardingSphere BOM 确保所有模块使用兼容的版本,消除版本冲突并简化依赖管理。
ShardingSphere BOM (shardingsphere-bom) 是一个包含所有 ShardingSphere 模块版本信息的 POM 文件。通过在项目中导入 BOM,您不再需要为单个 ShardingSphere 依赖指定版本。
要在 Maven 项目中使用 ShardingSphere BOM,请在您的 pom.xml 中添加以下配置:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-bom</artifactId>
<version>${shardingsphere.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
导入 BOM 后,您可以声明 ShardingSphere 依赖而无需指定版本:
<dependencies>
<!-- ShardingSphere JDBC 驱动 -->
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc</artifactId>
</dependency>
<!-- MySQL SQL 解析器 -->
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-parser-sql-engine-mysql</artifactId>
</dependency>
<!-- 数据源池实现 -->
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-data-source-pool-hikari</artifactId>
</dependency>
</dependencies>
对于 Gradle 用户,您可以通过 dependencyManagement 插件使用 BOM:
plugins {
id 'java'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}
dependencyManagement {
imports {
mavenBom "org.apache.shardingsphere:shardingsphere-bom:${shardingsphereVersion}"
}
}
dependencies {
implementation 'org.apache.shardingsphere:shardingsphere-jdbc'
implementation 'org.apache.shardingsphere:shardingsphere-parser-sql-engine-mysql'
}
