Skip to content

build(native): drop the HikariCP metadata copy, keep our own HikariCP reflection - #824

Merged
huayanYu merged 2 commits into
baomidou:devfrom
linghengqian:refactor/hikaricp-native-metadata
Oct 20, 2026
Merged

huayanYu merged 2 commits into
baomidou:devfrom
linghengqian:refactor/hikaricp-native-metadata

Conversation

@linghengqian

Copy link
Copy Markdown
Contributor

目标分支 / Target branch:请选 dev(main 只接收来自 dev 的发版合并,误选会被自动提醒)。
Please choose dev as the base branch — main only receives release merges from dev.

变更类型 / What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style (formatting, no behaviour change)
  • Refactor
  • Build / CI
  • Doc
  • Other, please describe:

描述 / The description of the PR

说明为什么需要这个改动,而不只是改了什么;关联对应的 issue(Fixes #123)。

Refs #820. This is the HikariCP part. The Druid part still waits for oracle/graalvm-reachability-metadata#10927.

com.zaxxer/HikariCP/6.3.3 in dynamic-datasource-native-metadata mixed two kinds of entries. Some are HikariCP's own metadata, which belongs in oracle/graalvm-reachability-metadata and is already there. The others are reflection that dynamic-datasource itself does on HikariCP types. This PR keeps the second kind, under the name of the module that makes the call, and drops the first.

This PR has two commits:

  1. build(native): move our HikariCP reflection under the modules that make it
    • New com.baomidou/dynamic-datasource-creator/reachability-metadata.json: the public methods of HikariConfig, for HikariDataSourceCreator.fetchMethod() and ConfigMergeCreator.setField(), and the no-arg constructor that ConfigMergeCreator.create() calls. The constructor entry moves over from com.baomidou/dynamic-datasource-native-metadata with its condition unchanged.
    • New com.baomidou/dynamic-datasource-spring/reachability-metadata.json: HikariDataSource.close(), for DefaultDataSourceDestroyer.destroy() and ItemDataSource.close(), and HikariDataSource.getHikariPoolMXBean() and HikariPool.getActiveConnections(), for HikariDataSourceActiveDetector.
    • Each entry is conditioned on the class that makes the call instead of on the HikariCP type. The folders are named after the Maven modules those classes live in. The files stay in dynamic-datasource-native-metadata, which is still the one module the Boot 3/4 starters get their metadata from.
  2. build(native): drop the HikariCP metadata that the upstream repository covers: the two entries left, HikariConfig allDeclaredFields and ConcurrentBag$IConcurrentBagEntry[], are in oracle's HikariCP 7.0.2 metadata. NBT selects that file for the test runtime classpath of both starters. Boot 4 resolves HikariCP 7.0.2. Boot 3.5.7 resolves 6.3.3, which is in no tested-versions list, so NBT falls back to the latest entry, 7.0.2.

Both commits update the layout comment in dynamic-datasource-native-metadata/build.gradle and the note in CONTRIBUTING.md 2.1.

影响面 / Impact on the core contracts

本框架的核心契约很窄,改动通常会波及其中之一,请勾选并说明:

  • @DS 解析 / DynamicDataSourceContextHolder 的切换与栈语义(含多层嵌套、同类内部调用)
  • 数据源创建与连接池参数(creator、Druid/HikariCP/beecp/c3p0/dbcp2/UCP)
  • 事务语义(@DSTransactional、savepoint、XA/Atomikos、Seata)
  • 分组与负载均衡(GroupDataSource、strategy)
  • ENC(...) 加解密 / 配置属性(新增或改名配置项)
  • 构建产物(模块划分、POM 依赖范围 api/compileOnly、JDK 基线)
  • 以上均不涉及

新增/改名配置项时,请同步文档 https://doc.xiuceyun.cn 与 DynamicDataSourceProperties 的 Javadoc。

The published dynamic-datasource-native-metadata jar no longer carries HikariCP's own metadata. A native build now gets it from the GraalVM reachability metadata repository, which the NBT Gradle and Maven plugins enable by default. A build that turns the repository off loses HikariConfig allDeclaredFields, and new HikariDataSource(config) then fails in HikariConfig.copyStateTo(), as the last removal check below shows. The POMs do not change.

自检清单 / Checklist

  • 本地在 JDK 17+ 下 ./gradlew clean test 通过(Gradle 客户端要求 17+;Boot 2 线模块由 JDK 8 toolchain 编译测试)
  • 涉及 Boot 3/4 特有 API 时,对应 starter 模块也构建通过:./gradlew build
  • 为行为变更补充/调整了单元测试
  • 新文件带有 license header(Copyright © 2018 organization baomidou)
  • 没有引入新的三方依赖;若必须引入,已在 PR 描述中说明理由与替代方案对比
  • 考虑了 GraalVM Native Image 影响(反射/代理注册),必要时说明为何 nativeTest 可能失败
  • commit message 采用 conventional 前缀(fix: / feat: / build: / docs: …),一个 commit 做一件事

No test is added: the change only moves and removes metadata, and the existing AddRemoveDatasourceTest and endpoint scenarios already fail in nativeTest without it (see below). The only new files are the two JSON files, and JSON has no place for a license header, like the existing metadata files.

其他信息 / Other information

Verified locally with GraalVM CE 25.4.4.1 (JDK 25.0.4.1) running Gradle, on dev @ 7c321c1 plus this change. NBT used reachability metadata repository version 1.0.14.

  • ./gradlew clean build --no-build-cache: all modules pass, with all 65 tasks executed (Boot 2/3/4 starters: 47/52/48 tests).
  • nativeTest for dynamic-datasource-spring-boot3-starter (52 found, 46 passed, 6 skipped) and dynamic-datasource-spring-boot4-starter (48 found, 46 passed, 2 skipped): pass.
  • To check that nativeTest notices each part, I ran the Boot 4 nativeTest in a throwaway worktree with one part taken out at a time:
    • Without com.baomidou/dynamic-datasource-spring, 10 AddRemoveDatasourceTest cases fail. Eight get MissingReflectionRegistrationError: Cannot reflectively invoke method 'public void com.zaxxer.hikari.HikariDataSource.close()', and in the two graceful-removal cases the pool never closes.
    • Without com.baomidou/dynamic-datasource-creator, 11 tests fail. Ten get Cannot reflectively invoke constructor 'public com.zaxxer.hikari.HikariConfig()', and the endpoint test's context does not load.
    • With only the constructor left in com.baomidou/dynamic-datasource-creator, 10 tests fail with Cannot reflectively invoke method 'public void com.zaxxer.hikari.HikariConfig.setConnectionTimeout(long)'.
    • With excludedModules.add('com.zaxxer:HikariCP') in metadataRepository, 11 tests fail with Cannot reflectively read or write field 'private volatile int com.zaxxer.hikari.HikariConfig.maxPoolSize'. HikariDataSource(HikariConfig) calls copyStateTo(), which copies every declared field by reflection.
  • A CollectReachabilityMetadata task registered on each starter's testRuntimeClasspath through an init script copied oracle's HikariCP 7.0.2 file for both starters, byte for byte.

Two of the entries are not reached by any test, before or after this PR:

  • Nothing in the shared scenarios calls ItemDataSource.close(). A stack trace printed from it during the Boot 4 JVM tests never showed up. So the HikariDataSource.close() entry conditioned on ItemDataSource is not exercised.
  • No scenario sets lazy: true, so HikariDataSourceCreator.createDataSource() never calls copyStateTo through configCopyMethod. The HikariConfig public methods it needs are registered under both HikariDataSourceCreator and ConfigMergeCreator. Both conditions are met as soon as HikariDataSourceCreator initialises, so the checks above cannot tell the two entries apart.

…ke it

com.zaxxer/HikariCP/6.3.3 mixed HikariCP's own metadata with reflection that
dynamic-datasource itself does on HikariCP types. Move the latter into
com.baomidou/dynamic-datasource-creator and com.baomidou/dynamic-datasource-spring,
named after the module that makes each call, and condition every entry on the
calling class instead of on the HikariCP type.

In dynamic-datasource-creator, HikariDataSourceCreator.fetchMethod() and
ConfigMergeCreator.setField() need the public methods of HikariConfig. The
no-arg constructor that ConfigMergeCreator.create() calls moves over from
com.baomidou/dynamic-datasource-native-metadata with its condition unchanged.
In dynamic-datasource-spring, DefaultDataSourceDestroyer.destroy() and
ItemDataSource.close() look up HikariDataSource.close(), and
HikariDataSourceActiveDetector calls HikariDataSource.getHikariPoolMXBean()
and HikariPool.getActiveConnections().

Only HikariCP's own two entries are left in com.zaxxer/HikariCP/6.3.3.

Refs baomidou#820
…y covers

The two entries left in com.zaxxer/HikariCP/6.3.3 are HikariCP's own:
HikariConfig allDeclaredFields, which HikariConfig.copyStateTo() needs, and
ConcurrentBag$IConcurrentBagEntry[]. oracle/graalvm-reachability-metadata has
both in its HikariCP 7.0.2 metadata, and both starters enable that repository
for nativeTest. Boot 4 resolves HikariCP 7.0.2. Boot 3.5.7 resolves 6.3.3,
which is in no tested-versions list, so NBT falls back to the latest entry,
7.0.2, there too.

Refs baomidou#820
@github-actions github-actions Bot added the documentation Docs and wiki label Oct 19, 2026
@huayanYu
huayanYu merged commit fd5231a into baomidou:dev Oct 20, 2026
12 checks passed
@linghengqian
linghengqian deleted the refactor/hikaricp-native-metadata branch October 20, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Docs and wiki

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants