Raspberry
Raspberry

Reputation: 337

Cannot import javax.validation.constraints in IntelliJ IDEA

I can't import that simple library, i have all jar files, also i tried Ivalidate Caches / Restart. Maybe i have to add validation to build path, but i don't know to which file. enter image description here

Upvotes: 4

Views: 24794

Answers (6)

Bruno
Bruno

Reputation: 1

Try this,

Step-by-step:

  1. Open "build.gradle" file. It's in your root folder project;

  2. Include the line below inside "dependencies{ }": implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'

  3. Save and close build.gradle file;

  4. Next, you will see a short notification on the top of your screen to "Load Gradle Changes". Click on it.

If you don't see any notification, click on Gradle side bar, and then click on "Reload All Gradle Projects".

  1. That's all! Your annotation @Valid, @NotBlank ou @NotNull, will work.

Upvotes: 0

ARMAN 阿尔曼
ARMAN 阿尔曼

Reputation: 1334

You just need to add spring-boot-starter-validation dependency in build.gradle file

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-validation'
}

Upvotes: 4

marcfreir
marcfreir

Reputation: 65

You just need to add the dependency Validation API in the pom.xml:

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

Links: https://www.baeldung.com/javax-validation

Upvotes: 7

Will
Will

Reputation: 7057

If you get this error after attempting to import a Maven project, it may be that you need to check "Import Maven projects automatically" in the Import Project wizard. Without that the IntelliJ build may not be able to locate Maven dependencies, even if they are declared in pom.xml files.

Upvotes: -1

Raspberry
Raspberry

Reputation: 337

Got it.

  1. File -> Project Structure
  2. In Modules click Dependecies, then click green "+" on the right side
  3. Click JARs or directiories... and add JAR files
  4. Click OK

    THEN:

  5. File -> Project Structure
  6. In Artifacts click FIX button on right bottom size
  7. Click OK

Upvotes: 6

michalsamek
michalsamek

Reputation: 136

What build tool do you use? You obviously forgot to declare your dependencies, that's why IDEA doesn't know where to look for the classes you are trying to import.

Upvotes: 2

Related Questions