Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

503
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda