When developing Spring Boot application with MySQL database using MySQL JDBC Driver (MySQL Connector/J), you may get the following error in the Maven project file (pom.xml):

'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.



So far I have shared with you the cause, reason and solution to fix the error MySQL JDBC driver dependency version is missing. Hope you find this post helpful.

Watch the video below to see how I fixed this error in a real life project:

 

Spring Boot and Database Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment

   


Comments 

#1G JOSEPH2024-01-14 15:36
mysql
mysql-connector-java
runtime



adding the runtime tag along the spring-batch depencies got it fixed.
Quote