【问题标题】:JJWT dependency confusionJJWT 依赖混淆
【发布时间】:2020-11-30 10:32:28
【问题描述】:

我继承了一个在 POM.xml 中有这个的 java 项目:

<properties>
    <jjwt.version>0.11.1</jjwt.version>
</properties>

// from https://github.com/jwtk/jjwt#maven
<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt-api</artifactId>
    <version>${jjwt.version}</version>
</dependency>
<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt-impl</artifactId>
    <version>${jjwt.version}</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt-jackson</artifactId> <!-- or jjwt-gson if Gson is preferred -->
    <version>${jjwt.version}</version>
    <scope>runtime</scope>
</dependency>

// what is this "jjwt" dep, and why might it be using a different version?
<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt</artifactId>
    <version>0.9.1</version> 
</dependency>

这个“jjwt”dep 是什么,为什么它可能使用不同的版本?

我在https://github.com/jwtk/jjwt 没有看到任何提及

但它在这里:https://mvnrepository.com/artifact/io.jsonwebtoken

【问题讨论】:

    标签: java jwt jjwt


    【解决方案1】:

    在 JJWT 版本 0.10.0 之前,API 和实现都被打包为单个工件 io.jsonwebtoken:jjwt

    从版本 0.10.0 开始,API 和实现被拆分为两个不同的工件。

    摘自JJWT Release Notes, version 0.10.0

    JJWT 的新模块化设计利用了编译和运行时依赖项之间的区别,以确保您只依赖在您的应用程序中可以安全使用的公共 API。所有内部/私有实现类都已移至新的 jjwt-impl 运行时依赖项。

    如果您过去依赖于任何内部实现类,您有两种选择:

    • 重构您的代码以使用 jjwt-api .jar 中的仅公共 API 类和接口。您可能在内部实现中使用过的任何功能都应该可以通过该 .jar 中更新的更干净的接口和帮助程序类获得。

    • 将新的 jjwt-impl .jar 指定为不作为运行时依赖项,而是作为编译依赖项。这将使您升级到 JJWT 0.10.0 完全向后兼容,但您需要自行承担风险。 JJWT 将在 jjwt-impl .jar 中做出任何语义版本兼容性保证。但是,在所有其他 JJWT 依赖项中都将非常小心地遵守语义版本控制。


    我的猜测是您的项目团队刚刚从 JJWT = 0.10。

    【讨论】:

    • 我在发行说明中错过了这一点。这就是我认为的情况,但想确定一下。感谢您的链接
    猜你喜欢
    • 2021-06-29
    • 1970-01-01
    • 2015-01-16
    • 1970-01-01
    • 2013-09-25
    • 2011-12-16
    • 2018-12-16
    • 1970-01-01
    • 2017-01-31
    相关资源
    最近更新 更多