PlantUML is a very useful tool for designing the UML diagrams. Things can be done easily such as Sequence Diagram, Data Model Diagram, Component Diagram. I'm really the big fan of this powerful software.
Storing PlantUML files in a Git repository is also best practice that you should follow. I'm prefer of doing by cloning the PlantUML's repository into my WSL2 path. Then you can launch the VSCode inside WSL2 by just entering the Path in WSL2 and run the command "code .".
How to start using PlantUML inside VSCode and WSL2?
- Yes, you need to install VSCode and WSL2 first. I'll skip the steps of doing these.
- Run your VSCode and install the extension name: "Remote - WSL"
- After that, install the extension "PlantUML". At this step you may get confused because VSCode is showing you to install PlantUML both "local" and "wsl". This is because VSCode knows that you have installed WSL2, your extension can be run locally (Windows) or WSL2 (Ubuntu for example). I do prefer to run "PlantUML" on WSL2 as Ubuntu is the most easiest of software installation when compare to Windows.
I have done all above steps but I can't still export or preview my diagram
- If you are using "Local" rendering option in PlantUML settings you have to install "Java" and "Graphviz" in your WSL2 first. Just simply run below commands.
sudo apt-get update sudo apt install openjdk-17-jre-headless sudo apt install graphviz
- Modify your PlantUML settings to make sure that the current rendering setting is set to "Local". Inside VSCode hit "ctrl+shift+p" and search for "Preferences" and entering the first suggested list.
- Inside the "Preferences" search for "plantuml" and click on the link of "Edit in settings.json".
- Make sure that you have set "plantuml.render" to "Local".
Then you can draw an easy diagram to test the preview or export the diagram.
BTW, you can use another option to render the diagram by using server which can be run by using Docker inside WSL2. I do not prefer using doing this because Docker is not automatically start on WSL2 so manually run the command to start the PlantUML server is too risky if you forgot to do that. Check this out for more information about the extension.