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/template engine — 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/template on the same templates.

2. Modules

Artifact Description

org.alexmond:gotmpl4j-core

The engine: lexer -> parser -> AST -> executor. Go builtins only; functions are pluggable via ServiceLoader.

org.alexmond:gotmpl4j-sprig

The Sprig function library, auto-discovered when on the classpath.

org.alexmond:gotmpl4j-spring

Spring-context template functions — msg (i18n), env (config), bean, and Spring Security helpers. See Spring context functions.

org.alexmond:gotmpl4j-spring-boot-starter

Spring Boot auto-configuration: engine bean, configuration properties, compile cache, function beans, and an optional ViewResolver.

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

4. API documentation

Versioned Javadoc for each artifact is published on javadoc.io (the version switcher there lets you jump between releases):

5. License

Apache License 2.0.