How to Fix MySQL connector Java dependency version is missing
- Details
- Written by Nam Ha Minh
- Last Updated on 28 October 2023   |   Print Email
'dependencies.dependency.version' for mysql:mysql-connector-java:jar is missing.
The dependency of MySQL Connector/J is declared as follows:<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency>This was working before, but after upgrading to Spring Boot 3.x you get the error message saying that the dependency version for mysql-connector-java is missing.So why is that?It’s because Spring 2.x and older supports the dependency mysql:mysql-connector-java with default version declared in the spring-boot-starter-parent’s POM. Since Spring Boot 3.x, the coordinates of the MySQL JDBC driver has changed from mysql:mysql-connector-java to com.mysql:mysql-connector-j for better reflecting the dependencies naming convention, e.g. groupId must be the reverse domain name of the organization.Having said that, the solution to fix the error MySQL connector Java dependency version is missing is declaring the MySQL JDBC driver dependency as shown below:
<dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency>Spring Boot 3.x declares the default version for this dependency so you won’t see such error again.NOTE: A workaround is specifying the dependency version explicitly like this:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.33</version> <scope>runtime</scope> </dependency>However, this is not a recommended solution as you might not know the exact version that is compatible with the version of Spring Boot.
Spring Boot and Database Tutorials:
- How to use JDBC with Spring Boot
- Spring Boot Connect to MySQL Database Examples
- Spring Boot Connect to Microsoft SQL Server Examples
- Spring Boot Connect to Oracle Database Examples
- Spring Boot Connect to PostgreSQL Database Examples
- Spring Boot Connect to H2 Database Examples
Comments
mysql-connector-java
runtime
adding the runtime tag along the spring-batch depencies got it fixed.