gradlequarkus

Trigger custom generator when file is saved


I am using the Quarkus with Gradle (without Kotlin) as a build tool.

In my project there are classes that contain some information that my custom generator uses to generate some custom classes. With the current implementation, the generator is triggered every time one starts an application or build.

Now I tried to implement a solution to trigger the generator every time one changes something in a class (e.g. add a new private variable) and save the changes.

The classes which generateor uses are all located in:

 '/src/main/java/core/data' 

Since I didn't manage to implement it, my question is: is it possible, and if so, how can it be done?

EDIT: Let's say I want to have JPA Metamodel Generator (https://docs.jboss.org/hibernate/orm/5.4/topical/html_single/metamodelgen/MetamodelGenerator.html) implemented in such a way. So each time one of the files in '/src/main/java/core/data' is changed and saved, the generetor would start the execution.


Solution

  • This seems like you want to write an annotation processor. This gives you some help writing such an annotation processor: https://www.baeldung.com/java-annotation-processing-builder

    And from Gradle you can set it up like this: https://docs.gradle.org/current/userguide/java_plugin.html#ex-declaring-annotation-processors