Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Makefile for use with PlantUML diagrams
DIAGRAMS_SRC := $(wildcard diagrams/*.plantuml)
DIAGRAMS_PNG := $(addsuffix .png, $(basename $(DIAGRAMS_SRC)))
DIAGRAMS_SVG := $(addsuffix .svg, $(basename $(DIAGRAMS_SRC)))
# Default target first; build PNGs, probably what we want most of the time
png: plantuml.jar $(DIAGRAMS_PNG)
# SVG are nice-to-have but don't need to build by default
svg: plantuml.jar $(DIAGRAMS_SVG)
# clean up compiled files
rm -f plantuml.jar $(DIAGRAMS_PNG) $(DIAGRAMS_SVG)
# If the JAR file isn't already present, download it
curl -sSfL $(PLANTUML_JAR_URL) -o plantuml.jar
# Each PNG output depends on its corresponding .plantuml file
diagrams/%.png: diagrams/%.plantuml
java -jar plantuml.jar -tpng $^
# Each SVG output depends on its corresponding .plantuml file
diagrams/%.svg: diagrams/%.plantuml
java -jar plantuml.jar -tsvg $^
# Quirk of GNU Make:
.PHONY: png svg clean
Copy link

hjst commented Jun 6, 2017


  • GNU make installed — (dnf|apt|yum) install make or install the Apple developer tools on Mac
  • Graphviz installed — (dnf|apt|yum) install graphviz or brew install graphviz on Mac
  • A working Java install — varies too much by platform, dnf install java-1.8.0-openjdk on Fedora
  • One diagram per file; files have the .plantuml extension and live in the diagrams/ directory relative to this Makefile

Example usage

$ tree docs/
├── diagrams
│   ├── components.plantuml
│   ├── seq-request-a.plantuml
│   ├── seq-session-create.plantuml
├── Makefile

$ cd docs
$ make
    ...make downloads the .jar file
    ...make compiles PNG files by default; use `make svg` for SVG files

$ tree
├── diagrams
│   ├── components.plantuml
│   ├── components.png
│   ├── seq-request-a.plantuml
│   ├── seq-request-a.png
│   ├── seq-session-create.plantuml
│   ├── seq-session-create.png
├── Makefile

Note: you'll probably want to add plantuml.jar to your .gitignore file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment