Migrating to java 17 mandatory module system, where do I find module javax.validation?

2.8k views Asked by At

I am upgrading my multi-maven-module project to be compatible with Java 17, since it is likely the rest of the enterprise ecosystem will demand it soon. So my main concern right now is providing module-info.java for all modules. It is one to one maven modules to java modules, at least so far.

The tricky part is providing the dependencies (module "requires" keyword), since the project was started with Java 8 and a lot has changed since.

I started with jdeps to get a bare minimum module-info.java for each module. Then, the typical cycle is executing mvn clean install and see where it complains that some "module is not visible" and adding the corresponding requires line in the module-info.java. So far so good.

Until I reached javax.validation module is not visible. This corresponds to my maven dependency

  <dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>2.0.1.Final</version>
  </dependency>

I tried different

requires javax.validation;
requires javax.validation.api;
requires ...

but didn't get it to work; it then fails compilation complaining that it cannot find javax.validation, javax.validation.api or whatever you placed in that requires line.

I have read a lot of resources about migrating, about the java module system, about validation, but nothing solved the problem.

Where do I get the java module for the javax.validation dependency?

1

There are 1 answers

1
manuelvigarcia On BEST ANSWER

javax.validation is not available as a Java module.

The options you have are:

  • java.validation
  • jakarta.validation

So the line needed is:

requires jakarta.validation;

or

requires java.validation;

The latest version of the Jakarta Validation API is 3.0.2, as seen in this repository.

<!-- https://mvnrepository.com/artifact/jakarta.validation/jakarta.validation-api -->
<dependency>
    <groupId>jakarta.validation</groupId>
    <artifactId>jakarta.validation-api</artifactId>
    <version>3.0.2</version>
</dependency>

Find the Jakarta Validation specification here. 3.0 is current, while 3.1 is under development. Hibernate Validator is the sole implementation for 3.0 & 3.1.