Maven Plugin
jte provides a Maven Plugin that you can integrate in your build process to either precompile templates, or to generate the Java/Kotlin code for your templates.
Versions alignment
Make sure the jte maven plugin version matches the jte dependency version. You can create a ${jte.version}
property to sync the versions easily.
The plugin provides two goals:
precompile
goal¶
See Precompiling Templates for more information. To use and configure this goal, you would use:
Configurations¶
The default phase for this goal is process-classes
, and it accepts the following configuration options:
Parameter | Description | Default |
---|---|---|
sourceDirectory |
The directory where template files are located | None. Required configuration. |
targetDirectory |
The directory where compiled classes should be written to | None. Required configuration. |
compilePath |
The compile-classpath to use | project.compileClasspathElements |
contentType |
The content type of all templates. Either Plain or Html |
None. Required configuration |
trimControlStructures |
Trims control structures, resulting in prettier output | false |
htmlTags |
Intercepts the given html tags during template compilation | None |
htmlPolicyClass |
An HtmlPolicy used to check the parsed HTML at compile time |
None |
htmlCommentsPreserved |
If HTML comments should be preserved in the output | false |
binaryStaticContent |
If to generate a binary content resource for each template | false |
compileArgs |
Sets additional compiler arguments for jte templates. |
See note below |
kotlinCompileArgs |
Sets additional compiler arguments for kte templates |
None |
packageName |
The package name, where template classes are generated to | Constants.PACKAGE_NAME_PRECOMPILED |
keepGeneratedSourceFiles |
If it should keep all generated jte source files after compilation | false |
About htmlPolicyClass
The htmlPolicyClass
will default to gg.jte.html.OwaspHtmlPolicy
if the content type is Html
.
About compileArgs
This option default depends on the maven.compiler.release
or, if it is absent, on maven.compiler.source
and maven.compiler.target
properties.
So, if the following property is configured in your pom.xml
:
The compileArgs
will default to --release 21
. If maven.compiler.release
is not configured, it will try to use maven.compiler.source
and maven.compiler.target
instead:
This will result in --source 21 --target 21
as the default value for compileArgs
. If none of those properties are configured, then the default value will be empty. Release is usually preferred over source and target since it will also ensure the correct API versions are used. See more details in the links below:
- Maven Compiler Plugin
-release
option-source
and-target
options
Clean all before precompiling
The precompile
goal cleans the directory containing the compiled template classes every time it runs. In your local development environment, it may make more sense to use hot reloading.
generate
goal¶
This goal generates all template classes in a source directory. This only generates .java
files, but does not compile them to .class
files.
Configurations¶
The default phase for this goal is generate-sources
, and it accepts the following configuration options:
Parameter | Description | Default |
---|---|---|
sourceDirectory |
The directory where template files are located | None. Required configuration. |
targetDirectory |
Destination directory to store generated templates. | ${project.build.directory}/generated-sources/jte |
contentType |
The content type of all templates. Either Plain or Html |
None. Required configuration |
trimControlStructures |
Trims control structures, resulting in prettier output | false |
htmlTags |
Intercepts the given html tags during template compilation | None |
htmlCommentsPreserved |
If HTML comments should be preserved in the output | false |
binaryStaticContent |
If to generate a binary content resource for each template | false |
packageName |
The package name, where template classes are generated to | Constants.PACKAGE_NAME_PRECOMPILED |
targetResourceDirectory |
Directory in which to generate non-java files (resources) | None |
extensions |
Extensions this template engine should load | None |
Extensions¶
Currently, the following extensions exist:
gg.jte.models.generator.ModelExtension
¶
See details about it in the jte-models documentation.
Parameters¶
The following parameters are available for this extension:
Parameter | Description | Default |
---|---|---|
interfaceAnnotation |
The FQCN of the annotation to add to the generated interface | None |
implementationAnnotation |
The FQCN of the annotation to add to the generated implementation classes | None |
language |
The target language for the generated classes. Either Java or Kotlin |
Java |
includePattern |
A regular expression to only include certain templates | None |
excludePattern |
A regular expression to exclude certain templates | None |
Example¶
gg.jte.nativeimage.NativeResourcesExtension
¶
Version note
Available since jte 1.10.0.
An application jar with generated classes can be built into a native binary using GraalVM native-image. To support this, this extension generates the necessary configuration files to tell native-image
about classes loaded by reflection.