Polyglot Maven First Steps


I read with keen interest about Polyglot Maven a few days ago. I'd first heard rumors two years ago, but I thought it was dead. I thought it was a shame, and so tried to created a project which would process pom.json files. But I ceased working on it as turned out to be time consuming.

Maven pom.xml files are very verbose, and yet Gradle has not quite taken off. Would a pom.groovy fill the space? Lets find out!


Before you start, you must have Maven 3.3.1 installed. This has support for "Core Extension".


Firstly, create a sample application:

mvn archetype:generate \
	-DgroupId=test \
	-DartifactId=test-webapp \
	-Dversion=1.0.0-SNAPSHOT \
cd test-webapp

Set-up the Maven extensions:

mkdir .mvn
cat > .mvn/extensions.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>

Maybe make it a bit more of a challenge, add the Jetty and Failsafe plugins:


Then, convert the pom into Groovy:

mvn io.takari.polyglot:polyglot-translate-plugin:translate -Dinput=pom.xml -Doutput=pom.groovy
rm pom.xml

You can add some Groovy into the pom.groovy at the end of the build section:

$execute(id: 'hello', phase: 'verify') {
  println ""
  println "Hello! I am Groovy inside Maven. What? What am I doing here?? I'm confused. I guess we are friends now. Maybe."
  println ""

Now for the big show!

mvn verify


AFAIK, there is zero IDE support for non-XML poms. But… here is an amusing work-around…

plugin {
    groupId 'io.takari.polyglot'
    artifactId 'polyglot-translate-plugin'
    executions {
        execution {
            id 'create-pom-for-ide'
            phase 'generate-sources'
            goals {
                goal 'translate'
            configuration {
                input 'pom.groovy'
                output 'pom.xml'

This is an interesting development in the Maven eco-system. It is certainly a lot of fun to play around with.

Core Extension is not the only new feature in Maven 3.3.1, there is only per-project JVM and and Maven configuration that looks really useful to ensure you and your team, and your CI are using the same, correct set-up.


  1. Practical Java Domain Specific Language Tutorial
  2. ANTLR 4 and Maven Tutorial
  3. Reverse a Java ZIP into Maven Project
  4. Migrating to CircleCI
  5. A Reliable Push Button Release Pattern