/ BUILD, MAVEN, POLYGLOT

Polyglot everywhere - part 1

This is the era of polyglot! Proponents of this practice spread the word that you’ve to choose the language best adapted to the problem at hand. And with a single team dedicated to a microservice, this might make sense.

My pragmatic side tells me it means that developers get to choose the language they are developing with and don’t care how it will be maintained when they go away…​ On the other hand, my shiny-loving side just want to try - albeit in a more controlled environment, such as this blog!

Introduction

In this 3 parts serie, I’ll try to use polyglot on a project:

  • The first part is about the build system
  • The second part will be about the server side
  • The final part will be about the client-side

My example will use a Vaadin project built with Maven and using a simple client-side extension. You can follow the project on Github.

Polyglot Maven

Though it may have been largely ignored, Maven can now talk many different languages since its version 3.3.1 thanks to an improved extension mechanism. In the end, the system is quite easy:

  • Create a .mvn folder at the root of your project
  • Create a extensions.xml file
  • Set the type of language you’d like to use:
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
  <extension>
    <groupId>io.takari.polyglot</groupId>
    <artifactId>polyglot-yaml</artifactId>
    <version>0.1.8</version>
  </extension>
</extensions>

Here, I set the build "language" as YAML.

In the end, the translation from XML to YAML is very straightforward:

modelVersion: 4.0.0
groupId: ch.frankel.blog.polyglot
artifactId: polyglot-example
packaging: war
version: 1.0.0-SNAPSHOT
dependencies:
    - { groupId: com.vaadin, artifactId: vaadin-spring, version: 1.0.0.beta2 }
build:
    plugins:
        - artifactId: maven-compiler-plugin
          version: 3.1
          configuration:
            source: 1.8
            target: 1.8
        - artifactId: maven-war-plugin
          version: 2.2
          configuration:
            failOnMissingWebXml: false

The only problem I had was in the YAML syntax itself: just make sure to align the elements of the plugin to the plugin declaration (e.g. align version with artifactId).

Remember to check the POM on Github with each new part of the serie!

Nicolas Fränkel

Nicolas Fränkel

Developer Advocate with 15+ years experience consulting for many different customers, in a wide range of contexts (such as telecoms, banking, insurances, large retail and public sector). Usually working on Java/Java EE and Spring technologies, but with focused interests like Rich Internet Applications, Testing, CI/CD and DevOps. Also double as a trainer and triples as a book author.

Read More
Polyglot everywhere - part 1
Share this