ANTLR Tool version 4.10.1 used for code generation does not match the current runtime version 4.7ANTLR Runtime version 4.10.1

5.1k Views Asked by At

I'm not able to solve the problem with the version of Jaybird's libs package: jaybird-jdk17:3.0.10 where the antlr4-runtime:4.7 is conflicting with the hibernate-core6.1.5Final lib where there is another antlr4:4.10 .1 https://uploaddeimagens.com.br/imagens/vSObP0s

I've tried to change several other Jaybird dependencies but without success, I tried to change the hibernate libs and without success.

Entity

package com.aula.restiapi.entidade;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor
@AllArgsConstructor
@Data
@Table(name = "tb_users")
public class Usuario {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    private String email;
    private Double salary;
}

repository

package com.aula.restiapi.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.aula.restiapi.entidade.Usuario;

@Repository
public interface UsuarioRepository extends JpaRepository<Usuario, Long>{

    @Query("SELECT obj FROM User obj WHERE obj.salary >= :minSalary AND 
    obj.salary <= :maxSalary")
    Page<Usuario> searchBySalary(Double minSalary, Double maxSalary, Pageable pageable);
}

controller

package com.aula.restiapi.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.aula.restiapi.entidade.Usuario;
import com.aula.restiapi.repository.UsuarioRepository;

@RestController
@RequestMapping(value = "/users")
public class UserController {

    @Autowired
    private UsuarioRepository repository;
    
    @GetMapping
    public ResponseEntity<List<Usuario>> findAll() {
        List<Usuario> result = repository.findAll();
        return ResponseEntity.ok(result);
    }

    @GetMapping(value = "/page")
    public ResponseEntity<Page<Usuario>> findAll(Pageable pageable) {
        Page<Usuario> result = repository.findAll(pageable);
        return ResponseEntity.ok(result);
    
    }
    @GetMapping(value = "/search-salary")
    public ResponseEntity<Page<Usuario>> searchBySalary(@RequestParam(defaultValue = "0") Double minSalary, @RequestParam(defaultValue = "1000000000000") Double maxSalary, Pageable pageable) {
        Page<Usuario> result = repository.searchBySalary(minSalary, maxSalary, pageable);
        return ResponseEntity.ok(result);
    }
    
}

application.properties

spring.datasource.url:jdbc:firebirdsql:localhost/3050:C:/DB/BD_ARTISTS.FDB? 
        sql_dialect=3&charSet=utf-8
spring.datasource.username:SYSDBA
spring.datasource.password:masterkey
spring.datasource.driver-class-name=org.firebirdsql.jdbc.FBDriver
spring.jpa.database-platform=org.hibernate.community.dialect.FirebirdDialect
spring.jpa.show-sql: true
spring.jpa.properties.hibernate.format_sql=true
#logging.level.org.springframework=DEBUG
app.path.arquivos=/Users/Paulo/Pictures/SavedPictures
spring.servlet.multipart.max-file-size=30MB
spring.servlet.multipart.max-request-size=30MB

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>

        <version>3.0.0</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.aula</groupId>
    <artifactId>restiapi</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>restiapi</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.firebirdsql.jdbc</groupId>
            <artifactId>jaybird-jdk17</artifactId>
            <version>3.0.10</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.orm</groupId>
            <artifactId>hibernate-community-dialects</artifactId>
        </dependency>
        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>5.5.0</version>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
1

There are 1 best solutions below

1
On

You need to switch to using Jaybird 4.0.8. The problem is that Jaybird 4.0.7 and earlier used a grammar generated with ANTLR 4.7.2 (or earlier). Hibernate 6 upgraded to ANTLR 4.10 (or higher), and there was an incompatible change in ANTLR 4.10, which means the grammar of Jaybird cannot be loaded when ANTLR 4.10 or higher is on the classpath, and vice versa, grammars from libraries using ANTLR 4.10 or higher (like Hibernate) cannot be loaded if ANTLR 4.7.x is on the classpath.

Jaybird 4.0.8 fixed that by removing the reliance on ANTLR 4.7.2 by replacing it with a dependency-less parser.

As an aside, normally you should let Spring Boot handle the dependency version of Jaybird, but Spring Boot 3.0.0 currently defines version 4.0.7.java11.

In any case, remove your current Jaybird dependency (as you're depending on the deprecated artifactId jaybird-jdk17, which is for Java 1.7, not Java 17!) and add:

<dependency>
  <groupId>org.firebirdsql.jdbc</groupId>
  <artifactId>jaybird</artifactId>
  <version>4.0.8.java11</version>
</dependency>

I do recommend you check the Jaybird 4 release notes if there are any relevant or breaking changes for you.

If you upgrade to Spring Boot 3.0.1 or higher, you can use:

<dependency>
  <groupId>org.firebirdsql.jdbc</groupId>
  <artifactId>jaybird</artifactId>
</dependency>

and let Spring Boot manage the dependency version.

As an aside, I notice that you have a dependency on net.java.dev.jna:jna listed. If you added that because of Jaybird, then you should remove it. Jaybird only needs JNA when you use native or embedded connections, but your code uses a pure-java JDBC URL for Firebird, so there is no need to add JNA.