gotmpl4j
A pure-Java implementation of Go’s text/template engine,
with the Sprig function library. No Go toolchain, no
CGo, no native bindings — just the JVM.
It renders the same templates Helm, Hugo, and countless Go CLIs use, and is validated for
byte-for-byte parity across 1,305 conformance cases ported from Go’s own text/template /
html/template test suites and Sprig’s upstream tests — each rendered through the real Go
engine and Sprig funcmap for ground truth. See Conformance for the
breakdown.
1. Highlights
-
The full Go
text/templateengine — lexer, parser, AST, executor — and Go’s 19 built-in functions. -
The Sprig function library: strings, lists, dicts, math, crypto, date, semver, encoding, and more.
-
Contextual HTML auto-escaping ported from Go’s
html/template(opt-in). -
Spring Boot integration — a starter with a ready-to-inject engine and MVC/WebFlux
ViewResolver— in the separate gotmpl4j-spring-boot project. -
Pluggable functions via
ServiceLoader— drop a module on the classpath and its functions appear. -
Mainstream-engine throughput — renders in the same tier as FreeMarker, Pebble, and Mustache, and faster than native Go
text/templateon the same templates.
2. Modules
| Artifact | Description |
|---|---|
|
The engine: lexer -> parser -> AST -> executor. Go builtins only; functions are pluggable via |
|
The Sprig function library, auto-discovered when on the classpath. |
gotmpl4j-core has zero dependency on Sprig or any host application. Add gotmpl4j-sprig
for the Sprig functions.
|
Using Spring Boot? The starter and the Spring-context functions
( |
3. Next
-
Getting started — add the dependency and render your first template.
-
Template syntax — actions, pipelines, control flow, and the Go built-ins.
-
Sprig functions — the function catalog.
-
Conformance — how correctness is held to the Go and Sprig originals.
-
Performance — JMH benchmarks vs FreeMarker, Thymeleaf, Mustache, Pebble, and Go.
4. API documentation
Versioned Javadoc for each artifact is published on javadoc.io (the version switcher there lets you jump between releases):
-
gotmpl4j-coreAPI — the engine,GoTemplate, the function SPI. -
gotmpl4j-sprigAPI — the Sprig function library.