What are the benefits of writing a Maven plugin in Groovy over Java?

I'm going to write some Maven plugins to make life easier for R&D people. I'm thinking of writing a plugin in Groovy or Java.

The plugin will most likely be needed:

  • Use Git commands like checkout, clone, etc.
  • Download pom.xml files of specific artifacts from a remote repository (our internal Nexus)
  • Parse the pom.xml file to extract a few XML elements (e.g. SCM tags and specific elements that I need for my plugin).
  • Work with the file system (there is a directory, a directory is deleted, etc.).
  • Get metdata information from a pom file, such as a dependency.

Any advice that may come from your extensive experience writing plugins in both languages ​​will help me a lot!

+3
source share
1 answer

I have a lot of experience with both languages, and have also written several Maven plugins. I wrote them in Java because I had no choice, but if I had a choice, I would choose Groovy.

In my opinion, if performance is not absolutely critical, Groovy is usually a better choice than Java, no matter what you do. I say this because there is usually 30% -50% less code to write something in Groovy than in Java. Most of the code that you omit when using Groovy is what will be considered a Java code template.

Groovy compactness due to two factors

  • (, , , ..)
  • JDK. GDK Java. , Java 10-20 ( ). Groovy, :

    String fileContent = new File('/foo/bar/baz.txt').text
    

, GMaven Maven Groovy, , AbstractMojo, Java

, pom.xml. pom.xml , , , MavenProject.

+6

Source: https://habr.com/ru/post/1768600/


All Articles