I really like maven for the structured way it provides for defining and building a project. But sometimes I wish for a less verbose notation than the XML of the Project Object Model (POM). For example, gradles dependency notation is far shorter than mavens dependency declaration.
Looking for a less verbose way to declare a maven POM, I discovered polyglot maven. It are maven extensions that allow the maven POM to be written in another dialect than XML. Since you see YAML more and more I decided to try that dialect, and see if my maven descriptor would be clearer.
The minimum version of maven this works on, is maven 3.3.1. Since that version it’s possible to provide per project configuration. or extension of maven.
- Create a directory to work in,
{projectdir}
, and change into it. To register the extensions for maven, create a file
{projectdir}/.mvn/extensions.xml
and add the extension:Now it’s possible to write the maven POM in YAML,
pom.yml
:By using the yaml inline map, or dictionary notation declaring a dependency uses way less characters then when using XML.
Limitations
Although this looks great, there are some limitations to using maven polyglot. Mixing different dialects is not possible, and plugins depending on the XML format will not work with another dialect. I also could not get a multi module project working with polyglot yaml.