You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java 17集成Google BigQuery Storage库时因JPMS包冲突导致编译失败的解决咨询

Java 17集成Google BigQuery Storage库时因JPMS包冲突导致编译失败的解决咨询

大家好,我最近在Java 17环境下用Google BigQuery相关库做集成时碰到了一个JPMS包冲突的编译问题,折腾了一阵没搞定,想请教下有没有解决思路。

我的环境是用Maven管理依赖,Java 17作为编译和运行版本。在pom.xml里我用了Google的BOM来统一版本管理,同时引入了Spring的BigQuery Starter和两个Google官方的BigQuery相关依赖:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>libraries-bom</artifactId>
            <version>26.49.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-gcp-starter-bigquery</artifactId>
        <version>1.2.8.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-bigquery</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-bigquerystorage</artifactId>
    </dependency>
</dependencies>

同时在module-info.java里声明了两个模块依赖:

requires proto.google.cloud.bigquerystorage.v1;
requires grpc.google.cloud.bigquerystorage.v1;

结果哪怕我根本没在代码里用到这些库的任何类,编译项目时直接抛出了错误:

java: java.lang.reflect.InvocationTargetException
Modules google.cloud.bigquerystorage and grpc.google.cloud.bigquerystorage.v1 export package com.google.cloud.bigquery.storage.v1 to module spring.core

我查了下原因,确实这两个模块导出了同一个com.google.cloud.bigquery.storage.v1包,只是包内的类不同。根据Java 17的JPMS规范,确实不允许同一个模块从两个不同模块导入同一个包。但GitHub上Google的官方文档又明确推荐新开发项目使用Java 17,这就让我有点困惑了。

我目前能想到的唯一办法是把整个BigQuery相关库重新打包成一个大模块,但这个方案明显有很多缺点——比如维护成本高、没法及时跟进官方的版本更新,感觉不太现实。

想问问大家:是不是我在依赖配置或者模块声明上哪里做错了?或者有没有更合理的 workaround 可以解决这个JPMS包冲突的问题?

备注:内容来源于stack exchange,提问作者Kikosha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 10:23:04