Let say that I have defined some bean like that:
@Component
@Validated
public class MyComponent {
public void someMethod(@NotNull Integer myIntValue) {
System.out.println(myIntValue);
}
}
This is packaged into some jar file like: com.comppany:component:1.0.jar
This jar file needs to depend (include?) from:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.13.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>6.0.13.Final</version>
</dependency>
The question is: What if this jar file is added as dependency to another project where there is different JSR-303 validation implementation (Commons validator from apache for example)? Is there a way to protect from this situation? 1. Use one validation impl for "component" module and other for other? 2. or may be validate at compile time (how?) that target which imports "component" module have same JSR-303 validation?