A Gradle plugin for static asset optimization in Spring Boot / JVM web applications.
Minifies CSS, JavaScript, and HTML. Optimizes PNG, JPEG, and SVG files. Converts images to WebP. Uses esbuild, oxipng, and cwebp with zero runtime dependencies — native binaries are bundled inside the plugin JAR.
Apply the plugin and place your assets under src/main/resources/static/:
./gradlew buildAll supported file types are automatically optimized and included in the output JAR.
- CSS minification via esbuild (
**/*.css) - JavaScript minification via esbuild (
**/*.js) - HTML minification with Thymeleaf support (
**/*.html) — pure Java, no native binary - PNG lossless optimization via oxipng (
**/*.png) - JPEG metadata stripping (
**/*.jpg,**/*.jpeg) — pure Java - SVG optimization — removes comments, metadata, empty groups (
**/*.svg) — pure Java - WebP conversion via cwebp (converts PNG, JPEG to WebP)
- Automatic
src/main/resources/static/scanning - Hooks into
processResources— no extra task needed - Platform-specific native binary bundling
assetOptimizer {
sourceDirs = files("src/main/resources/static")
outputDir = layout.buildDirectory.dir("asset-optimizer")
}| Task | Description | Input |
|---|---|---|
minifyCss |
Minifies CSS files | **/*.css |
minifyJs |
Minifies JavaScript files | **/*.js |
minifyHtml |
Minifies HTML files | **/*.html |
optimizePng |
Lossless PNG optimization | **/*.png |
optimizeSvg |
SVG optimization | **/*.svg |
optimizeJpeg |
JPEG metadata stripping | **/*.jpg, **/*.jpeg |
convertWebp |
Converts PNG/JPEG to WebP | **/*.png, **/*.jpg |
All tasks run automatically as dependencies of processResources.
- At runtime, the plugin detects the current OS and architecture, extracts the matching native binary (esbuild, oxipng, or cwebp) to a temp directory, and uses it for optimization.
- The
processResourcestask is extended with all optimization tasks — no extra configuration required for basic use. - HTML, SVG, and JPEG optimizations use pure Java implementations — no native binaries required for these.
- Java 17+
MIT — see LICENSE for details.