|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// Copyright Red Hat Inc. and Hibernate Authors |
| 3 | +[[static-metamodel-processor]] |
| 4 | += Annotation processor |
| 5 | + |
| 6 | +include::../components/_incubating-warning.adoc[] |
| 7 | + |
| 8 | +[[static-metamodel-processor-enabling]] |
| 9 | +== Enabling the annotation processor |
| 10 | + |
| 11 | +Hibernate Search provides a dedicated annotation processor to generate the static metamodel classes. |
| 12 | +This annotation processor is located in the `org.hibernate.search:hibernate-search-metamodel-processor`. |
| 13 | + |
| 14 | +The annotation processor has to be added to the build, e.g. for Maven: |
| 15 | + |
| 16 | +==== |
| 17 | +[source,XML,subs="+attributes"] |
| 18 | +---- |
| 19 | +<plugin> |
| 20 | + <artifactId>maven-compiler-plugin</artifactId> |
| 21 | + <executions> |
| 22 | + <execution> |
| 23 | + <id>default-compile</id> |
| 24 | + <configuration> |
| 25 | + <annotationProcessors> |
| 26 | + <annotationProcessor>org.hibernate.search.metamodel.processor.HibernateSearchMetamodelProcessor</annotationProcessor> <1> |
| 27 | + </annotationProcessors> |
| 28 | + <annotationProcessorPaths> |
| 29 | + <path> |
| 30 | + <groupId>org.hibernate.search</groupId> |
| 31 | + <artifactId>hibernate-search-metamodel-processor</artifactId> <2> |
| 32 | + </path> |
| 33 | + <path> |
| 34 | + <groupId>org.hibernate.search</groupId> |
| 35 | + <artifactId>hibernate-search-backend-lucene</artifactId> <3> |
| 36 | + </path> |
| 37 | + </annotationProcessorPaths> |
| 38 | + </configuration> |
| 39 | + </execution> |
| 40 | + </executions> |
| 41 | +</plugin> |
| 42 | +---- |
| 43 | +
|
| 44 | +<1> Provide the fully qualified class name of the annotation processor that generates the metamodel. |
| 45 | +<2> Add the `org.hibernate.search:hibernate-search-metamodel-processor` dependency as an annotation processor path for the Maven compiler plugin to be able to actually find the processor. |
| 46 | +<3> Add the backend dependency, in this example, the <<backend-lucene,Lucene backend>>, as an annotation processor path. |
| 47 | +It is important to include the same backend that the application is using to make sure that the generated metamodel classes reflect all the backend specifics. |
| 48 | +For example, backends might have different defaults, resulting in a different set of field traits depending on the backend. |
| 49 | +
|
| 50 | +NOTE: The version of both annotation processor and backend dependencies are skipped in the definition of the annotation paths, as in case the Hibernate Search BOM is imported via dependency management, the compiler plugin will use the managed versions. |
| 51 | +This way the generated metamodel classes will be based on the same backend that the application uses. |
| 52 | +==== |
| 53 | + |
| 54 | +[[static-metamodel-processor-configuration]] |
| 55 | +== Configuration |
| 56 | + |
| 57 | +The annotation processor options are passed as the compiler arguments with the `-A` key: |
| 58 | + |
| 59 | +==== |
| 60 | +[source,XML,subs="+attributes"] |
| 61 | +---- |
| 62 | +<plugin> |
| 63 | + <artifactId>maven-compiler-plugin</artifactId> |
| 64 | + <executions> |
| 65 | + <execution> |
| 66 | + <id>default-compile</id> |
| 67 | + <configuration> |
| 68 | + <compilerArgs> |
| 69 | + <arg>-Aorg.hibernate.search.metamodel.processor.generated_annotation.timestamp=false</arg> <1> |
| 70 | + <arg><!-- ... --></arg> <2> |
| 71 | + </compilerArgs> |
| 72 | + <!-- ... --> <3> |
| 73 | + </configuration> |
| 74 | + </execution> |
| 75 | + </executions> |
| 76 | +</plugin> |
| 77 | +---- |
| 78 | +
|
| 79 | +<1> Pass the annotation processor parameters using the `-A` key. |
| 80 | +<2> Pass any other compiler arguments required by the build. |
| 81 | +<3> Further compiler plugin configuration. |
| 82 | +==== |
| 83 | + |
| 84 | +The following annotation processor configuration properties are available: |
| 85 | + |
| 86 | +[[static-metamodel-processor-configuration-generated_annotation-add]]`org.hibernate.search.metamodel.processor.generated_annotation.add`:: |
| 87 | +Description::: |
| 88 | +Whether to add the `@Generated` annotation to the generated static metamodel classes. |
| 89 | +Default value::: |
| 90 | +`true` |
| 91 | + |
| 92 | +[[static-metamodel-processor-configuration-generated_annotation-timestamp]]`org.hibernate.search.metamodel.processor.generated_annotation.timestamp`:: |
| 93 | +Description::: |
| 94 | +Defines whether the `@Generated` annotation includes the `date` attribute. |
| 95 | +Having the date attribute will result in non-reproducible builds, as the timestamp will be different for each compilation. |
| 96 | +Hence, it is disabled by default. |
| 97 | +Default value::: |
| 98 | +`false` |
| 99 | + |
| 100 | +[[static-metamodel-processor-configuration-add_generated_annotation]]`org.hibernate.search.metamodel.processor.backend.version`:: |
| 101 | +Description::: |
| 102 | +Explicitly define the backend version. By default, the processor will use the latest compatible version of the backend. |
| 103 | +This option can be used if the static metamodel is required for an older backend version. |
| 104 | +Default value::: |
| 105 | +`<latest>` |
| 106 | + |
| 107 | +[[static-metamodel-processor-limitations]] |
| 108 | +== Current annotation processor limitations |
| 109 | + |
| 110 | +While the annotation processor is in its early stages of development, it has a few limitations: |
| 111 | + |
| 112 | +* Any use of <<binding-valuebridge-valuebinder,custom binders>> will be ignored and should produce a compiler warning. |
| 113 | +This means that if the search entities rely on custom binders, fields that those binders produce will be missing from the generated metamodel. |
| 114 | +* <<mapper-orm-custom-annotations,Custom mapping annotations>> are not supported. |
| 115 | +* <<mapping-programmatic,Programmatic mapping>> is also unsupported by the annotation processor. |
| 116 | +As the annotation processor cannot easily read programmatic mapping definitions, this limitation is here to stay. |
0 commit comments