Skip to content

Support build-time SVG rendering in Maven/Gradle via the CLI - #282

Merged
brunoborges merged 1 commit into
mainfrom
brunoborges-add-maven-plugin
Sep 30, 2026
Merged

brunoborges merged 1 commit into
mainfrom
brunoborges-add-maven-plugin

Conversation

@brunoborges

Copy link
Copy Markdown
Owner

Description

#279 asks for a way to render SVG logos to PNG/JPEG at build time, for example PWA icons. The prototype for this is viritin/svg-render-maven-plugin. This PR does it without a new Maven plugin artifact: the build runs the existing CLI (io.brunoborges.jairosvg.cli.Main) in the same JVM, using exec-maven-plugin's java goal with jairosvg added as a plugin dependency. Gradle can do the same with a JavaExec task.

The CLI needed three small changes to work reliably inside a build:

  • Missing output parent directories are now created. Before, -o target/classes/META-INF/resources/icons/icon.png failed if the folder did not exist.
  • Headless AWT is now the default. Main sets java.awt.headless=true unless the property is already set. This matters because the CLI now runs inside the Maven JVM.
  • Invalid arguments are now rejected. Unknown options, options with no value, and non-numeric values throw IllegalArgumentException with a clear message. This way a typo such as --outputwidth fails the build instead of producing an image at the wrong size.
    • Behavior change: unknown flags used to be silently ignored. testUnknownFlagIgnored is replaced by tests for the rejection cases.

Docs:

  • New site page build-time-rendering.md, linked from the site menu and cli.md. It covers:
    • a basic Maven example
    • several sizes from one SVG (apple-touch-icon, 192, 512)
    • notes on output format and size
    • a generated-resources + build-helper alternative
    • a Gradle Kotlin DSL example
    • credit to the viritin prototype
  • New short README section with the Maven snippet.
  • Removed -i, --invert-images from the README CLI table, because the CLI never implemented it.
  • bump-version.sh now also updates the version shown in the new page.

Compared with the dedicated plugin, this gives up {size} placeholders, fingerprint-based incremental skipping, and automatic resource registration. In return there is no new artifact to release or maintain.

Validation:

  • Ran the recipe against a throwaway sample project using the locally installed snapshot. mvn package put a 512x512 PNG and a 192x96 JPEG into the jar. Changing an argument to the typo --outputwidth failed the build with Unknown option.
  • ./mvnw clean verify site: 1272 tests, 0 failures, and the new page was generated. The site step also logged a javadoc report error, but the build still succeeded.

Fixes: #279

Checklist

  • Tests pass: ./mvnw clean verify (BUILD SUCCESS, 1272 tests, 0 failures)
  • Code formatted: ./mvnw spotless:apply
  • Documentation updated (if applicable)
  • No breaking changes to public API (library API unchanged; the CLI now rejects unknown flags it used to ignore)

Harden the CLI for in-process use from exec-maven-plugin / Gradle JavaExec:
create missing output parent directories, default to headless AWT, and
reject unknown options, missing values, and invalid numbers. Add a
Build-time Rendering guide and README section.

Fixes: #279

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@brunoborges
brunoborges merged commit 41f8c43 into main Sep 30, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add Maven plugin

1 participant