How to resolve dependency conflict for spring boot 3 and hibernate search

2.1k views Asked by At

I habe the following dependencies within my data module:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.hibernate.search</groupId>
        <artifactId>hibernate-search-mapper-orm-jakarta</artifactId>
        <version>6.1.7.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.search</groupId>
        <artifactId>hibernate-search-backend-lucene</artifactId>
        <version>6.1.7.Final</version>
    </dependency>


+ org.hibernate.search:hibernate-search-mapper-orm-jakarta:6.1.7.Final
└── org.hibernate.common:hibernate-commons-annotations:5.1.2.Final
  + org.hibernate:hibernate-core-jakarta:5.6.11.Final
  └── org.hibernate.common:hibernate-commons-annotations:5.1.2.Final
  + org.hibernate.search:hibernate-search-mapper-pojo-base:6.1.7.Final
  └── org.hibernate.common:hibernate-commons-annotations:5.1.2.Final

+ org.springframework.boot:spring-boot-starter-data-jpa:3.0.5
└── + org.hibernate.orm:hibernate-core:6.1.7.Final
    └── org.hibernate.common:hibernate-commons-annotations:6.0.6.Final

The conflict is between hibernate-commons-annotations:5.1.2.Final from hibernate-search-mapper-orm-jakarta and hibernate-commons-annotations:6.0.6.Final from spring-boota-starter-data-jpa dependency.

I want to use hibernate search(with jakarta persistence) and spring boot 3.0.5. How can I achieve this. Can I somehow tell spring to use onother version of hibernate core?

Thanks and Best Regards Matt

2

There are 2 answers

0
John Williams On

You have two alternatives, lifting the hibernate-commons-annotations to 6.0.6.Final or dropping the hibernate-commons-annotations to 5.1.2.Final.

To lift the org.hibernate.search:hibernate-commons-annotations to 6.0.6.Final, simply exclude it from org.hibernate.search:hibernate-search-mapper-orm-jakarta:6.1.7.Final. Then hibernate-search-mapper-orm-jakarta will use the class provided via spring-boot-starter-data-jpa:3.0.5 via hibernate-core:6.1.7.Final

    <dependency>
        <groupId>org.hibernate.search</groupId>
        <artifactId>hibernate-search-mapper-orm-jakarta</artifactId>
        <version>6.1.7.Final</version>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate.common</groupId>
                <artifactId>hibernate-commons-annotations</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

To drop the hibernate-commons-annotations to 5.1.2.Final from the 6.0.6.Final arising from the org.springframework.boot:spring-boot-starter-data-jpa:3.0.5 dependency (which is loading org.hibernate.orm:hibernate-core:6.1.7 & hibernate-commons-annotations:6.0.6.Final) add the following pom dependency:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate.orm</groupId>
                <artifactId>hibernate-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

A possible problem with the second approach is that you lose the intermediate org.hibernate.orm:hibernate-core. It depends on what your code does. If required you can fix by adding the following pom dependency:

    <dependency>
        <groupId>org.hibernate.orm</groupId>
        <artifactId>hibernate-core</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate.common</groupId>
                <artifactId>hibernate-commons-annotations</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
0
Matt On

There are separate artifacts for jakarta as you can read in the documentation to hibernate search 6.1. And from there you are leaded to the proper artifacts:

  • org.hibernate.hibernate-core-jakarta:5.6.12.Final (or newer)
  • org.hibernate.search.hibernate-search-mapper-orm-jakarta:6.1.8.Final (or newer)

Then everything should work.