문제

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:

enter image description here

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top