Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

502
Views
Using Hibernate Validator Annotation Processor with Kotlin (and Gradle)

So I'm trying to get the Hibernate Validator Annotation Processor working in a Kotlin project, to check my JSR 380 annotations, with not much luck.

Unfortunately the documentation does not mention how to set it up with Gradle, and obviously with Kotlin we have to use "Kapt" to enable java annotation processors.

Hibernate Validator Annotation Processor Documentation: http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#validator-annotation-processor

Kapt Documentation: https://kotlinlang.org/docs/reference/kapt.html

I currently have the following config in my build.gradle file relating to the processor:

plugins {
    id "org.jetbrains.kotlin.kapt" version "1.3.11"
    ...
}

apply plugin: 'org.jetbrains.kotlin.kapt'
...

dependencies {
    implementation 'org.hibernate:hibernate-validator:6.0.14.Final'
    implementation 'org.glassfish:javax.el:3.0.1-b09'
    kapt 'org.hibernate:hibernate-validator-annotation-processor:6.0.14.Final'
    ...
}

kapt {
    arguments {
        arg('methodConstraintsSupported', 'false')
        arg('verbose', 'true')
    }
}

However whenever I build, I cannot see any output relating to the validator annotation processor and I do not get any build errors when deliberately applying an incorrect annotation (e.g. applying a @Min() annotation to a String field.

If someone could advise on how to get the processor working I would be eternally grateful! :)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I got this working in my build.gradle.kts like so (I'm using Kotlin Script as opposed to Groovy):

plugins {
    ...
    id("org.jetbrains.kotlin.kapt") version "1.3.72"
    ...
}

dependencies {
    ...
    kapt(
            group = "org.hibernate.validator",
            name = "hibernate-validator-annotation-processor",
            version = "6.0.2.Final"
    )
    ...
}

This correctly gave me errors when building, but only when I applied the validation annotation to the getter. When I was mistakenly applying it to just the constructor argument the validation did not work, and I saw no errors from the annotation processor. For example:

class Thing(
    @get:AssertTrue
    var name: String
)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!