Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Improving Maven Projects

DZone's Guide to

Improving Maven Projects

Maven has introduced new features, such as Lifecycle, Polyglot, and Wrapper, to improve efficiency and make it easier to share code.

· DevOps Zone
Free Resource

Download the blueprint that can take a company of any maturity level all the way up to enterprise-scale continuous delivery using a combination of Automic Release Automation, Automic’s 20+ years of business automation experience, and the proven tools and practices the company is already leveraging.

For a long time, Maven has been the defacto build tool and dependency management for Java projects. Some cool things have been added by plugins but now Maven has been enriched with new features improving on the others:

  • Maven Lifecycle
  • Maven Polyglot
  • Maven Wrapper

All these new features are thanks to Takiri, which is lead by Jason van Zyl (@jvanzyl), the Maven’s father.

Requirements:

  • Maven 3.3.1
  • Java 7

Maven Lifecycle

Avoid the re-compilation if there are no changes in the source code. You just need to complete two simple steps to enable this awesome feature. Save your time!

1. Add plugin below:


<build>
  <plugins>
    <plugin>
      <groupId>io.takari.maven.plugins</groupId>
      <artifactId>takari-lifecycle-plugin</artifactId>
      <extensions>true</extensions>
    </plugin>
  </plugins>
</build>


2. Switch your current packaging from jar to takari-jar.

You can see in the log that the plugin has taken effect. Now, if you have already compiled, you won't have to compile again unless you make changes to your source code.

Maven Polyglot

Building a pom file in xml format is verbose. Now, you can build your pom in different languages: atom, clojure, groovy, ruby, scala, yaml. And take advantage of each one.

Pre-requisite:

  1. Inside the project create .mvn/extensions.xml file, where language dependency will take place:

Atom:

<?xml version="1.0" encoding="UTF-8"?>
<extensions>
  <extension>
      <groupId>io.takari.polyglot</groupId>
      <artifactId>polyglot-atom</artifactId>
      <version>0.1.6</version>
  </extension>
</extensions>

Clojure:

<?xml version="1.0" encoding="UTF-8"?>
<extensions>
  <extension>
      <groupId>io.takari.polyglot</groupId>
      <artifactId>polyglot-clojure</artifactId>
      <version>0.1.6</version>
  </extension>
</extensions>

Groovy:

<?xml version="1.0" encoding="UTF-8"?>
<extensions>
  <extension>
      <groupId>io.takari.polyglot</groupId>
      <artifactId>polyglot-groovy</artifactId>
      <version>0.1.6</version>
  </extension>
</extensions>

Ruby:

<?xml version="1.0" encoding="UTF-8"?>
<extensions>
  <extension>
      <groupId>io.takari.polyglot</groupId>
      <artifactId>polyglot-ruby</artifactId>
      <version>0.1.6</version>
  </extension>
</extensions>

Scala:

<?xml version="1.0" encoding="UTF-8"?>
<extensions>
  <extension>
      <groupId>io.takari.polyglot</groupId>
      <artifactId>polyglot-scala</artifactId>
      <version>0.1.6</version>
  </extension>
</extensions>

Yaml:

<?xml version="1.0" encoding="UTF-8"?>
<extensions>
  <extension>
      <groupId>io.takari.polyglot</groupId>
      <artifactId>polyglot-yaml</artifactId>
      <version>0.1.6</version>
  </extension>
</extensions>

Would you like to migrate your xml to any other language? You can do it running the command below:

mvn io.takari.polyglot:polyglot-translate-plugin:translate -Dinput=pom.xml -Doutput=pom.{format}

Where format could be atomcljgroovyrbscala and yml.

Maven Wrapper

Sharing projects is common and sometimes we have specific versions from our build tool. Now, you don’t need to ask your friend which maven version you need if the maven project uses maven-wrapper. To do that, you just need to run:

mvn -N io.takari:maven:wrapper

Now you can make a build mvnw clean install. If you like to see which maven version you will download take a look at .mvn/wrapper/maven-wrapper.properties inside your project.

Download the ‘Practical Blueprint to Continuous Delivery’ to learn how Automic Release Automation can help you begin or continue your company’s digital transformation.

Topics:
maven ,java ,devops

Published at DZone with permission of Eddú Meléndez. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}