Issue
Which java validation package should be used in Spring Boot Apps
// validation api
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
implementation group: 'jakarta.validation', name: 'jakarta.validation-api', version: '3.0.2'
Solution
Each Spring Boot version documents the dependencies they rely on by default, see Dependency Versions (link follows most recent release, use this link specifically for Spring Boot 2.7.2).
Also, in general, you shouldn't need to worry about specifying these versions: they should be managed by Spring Boot for you.
As to JavaEE/JakartaEE dependencies, things are a bit more complicated because of the switch from javax.*
(JavaEE/JakartaEE 8 and lower) to jakarta.*
(JakartaEE 9 and higher) for the package namespace. For example, javax.validation:validation-api
uses the javax.*
package namespace exclusively, while jakarta.validation:jakarta.validation-api
uses javax.*
package namespace in the 2.0.x version, and the jakarta.*
namespace in the 3.0.x version.
Given Spring Boot 2.7 still uses the javax.*
package names, you need to use either javax.validation:validation-api:2.0.1.Final
or jakarta.validation:jakarta.validation-api:2.0.2
, as also shown in the Dependency Versions document I linked above (I recommend using jakarta.validation:jakarta.validation-api:2.0.2
).
You should not use jakarta.validation:jakarta.validation-api:3.0.2
, as it uses the wrong package namespace. You will need to wait for Spring Boot 3.0 to make that switch (but again, if you let Spring Boot manage your dependency version, like you should, then you shouldn't need to worry about this).
Answered By - Mark Rotteveel
Answer Checked By - Clifford M. (JavaFixing Volunteer)