gotmpl4j
A pure-Java implementation of Go’s text/template engine,
with the Sprig function library and an optional Spring
Boot starter. 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). -
A Spring Boot starter: a ready-to-inject engine, configuration properties, a compile cache, and an MVC/WebFlux
ViewResolver. -
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. |
|
Spring-context template functions — |
|
Spring Boot auto-configuration: engine bean, configuration properties, compile cache, function beans, and an optional |
gotmpl4j-core has zero dependency on Sprig or any host application. Add gotmpl4j-sprig
for the Sprig functions, or the starter for Spring Boot integration.
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.
-
Spring Boot starter — auto-configuration and the view resolver.
-
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. -
gotmpl4j-springAPI — Spring-context template functions (messages, config, beans, security, web). -
gotmpl4j-spring-boot-starterAPI — the Spring Boot integration.