Java Magazine, Jan/Feb 2017
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2017 18 tools ing plugins in sequence is all wired into Maven Under the hood the pom xml file is transformed into an actual POM of plain old Java objects POJOs This is where Polyglot for Maven comes into the picture It provides extensions to Maven that allow Maven to read other files such as pom rb in Ruby or pom groovy in Groovy parse them and create the POM from them While this appears simple there is as usual complexity in the details Maven Extensions If you have been using Maven at all you know that it is powered by many plugins that perform tasks such as copying and filtering resources compiling code running tests creating packages and many others Maven calls these plugins to perform the individual tasks Extensions by contrast offer modifications or additions to the core of Maven itself In the past you were obliged to create a JAR file and add it to the classpath to accomplish this and then you would have essentially created a custom Maven distribution And managing custom distributions of tools in a large organization or open source project turns out to be a difficult chore The extension loading mechanism in Maven on the other hand allows you to simply define an extension as part of your project and use the standard Maven distribution Extensions are available via the central repository just like plugins and dependencies To load them as part of your project build you declare them in an extensions xml file in the directory mvn located in the root folder of your project see Listing 2 Listing 2 xml version 10 encoding UTF 8 extensions extension groupId io takari polyglot groupId artifactId polyglot ruby artifactId version 0119 version extension extensions Plugins extend Maven by supporting different project lifecycles and goals so new packaging types and tasks can be performed In contrast extensions change the behavior of Maven itself Support for loading extensions and other configuration data via the mvn folder has been part of the standard Maven releases since version 331 Besides containing the file for loading extensions from a project local directory the mvn folder can also contain project specific configuration for JVM parameters and Maven options in the jvm config and maven config files respectively Markup Formats Polyglot for Maven provides extensions for Maven that enable it to load POM files written in diferent dialects The latest version is 0119 The community has developed many examples in the project These examples all contain the configuration for the relevant extensions Polyglot for Maven extensions use the groupId io takari polyglot and the artifactId value polyglot So in addition to the Ruby version from Listing 2 there are also polyglot yaml polyglot groovy polyglot scala and other extensions all of which are provided by the Polyglot for Maven project Listing 3 shows a sample Polyglot for Maven file in this case a minimal pom yaml file It contains the definition of the GAV coordinates and the setting of a property value Polyglot for Maven supports writing POM files using Groovy Ruby Clojure or Scala
You must have JavaScript enabled to view digital editions.