在球衣项目中包含jersey-bom导入范围依赖的目的是什么? [英] What is the purpose of including the jersey-bom import scoped dependency in a jersey project?

查看:454
本文介绍了在球衣项目中包含jersey-bom导入范围依赖的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



生成。



因为它存在于 dependencyManagement 中(不在依赖项),它实际上并没有为项目添加依赖项,它只是集中了版本管理。如果您不熟悉这些差异,请参阅此SO答案



基本上,BOM允许您根据需要添加尽可能多的球衣依赖性,而不必担心混合不良版本:

 <依赖性> 
< dependency>
< groupId> org.glassfish.jersey.containers< / groupId>
< artifactId> jersey-container-grizzly2-http< / artifactId>
<! - 由于物料清单需要不需要的版本 - >
< / dependency>
< dependency>
< groupId> org.glassfish.jersey.media< / groupId>
< artifactId> jersey-media-json-jackson< / artifactId>
<! - 由于物料清单需要不需要的版本 - >
< / dependency>
< / dependencies>


When generating a based project using the jersey-quickstart-grizzly2 artifact

mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 \
-DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
-DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example \
-DarchetypeVersion=2.7

The pom generated a jersey-bom dependency which can be deleted:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

And this dependency:

<dependency>
      <groupId>org.glassfish.jersey.containers</groupId>
      <artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>

this is how the maven dependency graph looks like:

What is the purpose of including the jersey-bom dependency in the project ?

解决方案

You should not delete the jersey-bom from dependencyManagement.

A BOM (bill of materials) packages related dependencies so that their versions will work together. You can read more about it in the maven docs on this page.

Because this lives in dependencyManagement (not in dependencies), it is not actually adding dependencies to your project, it's just centralizing version management. If you are not familiar with the difference, read more in this SO answer.

Basically, the BOM allows you to add as many jersey dependencies as you need without worrying about mixing bad versions:

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-grizzly2-http</artifactId>
        <!-- NO VERSION NEEDED BECAUSE OF THE BOM -->
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <!-- NO VERSION NEEDED BECAUSE OF THE BOM -->
    </dependency>
</dependencies>

这篇关于在球衣项目中包含jersey-bom导入范围依赖的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆