Gradle

Gradle – Flat Repo (flatdir)

What the heck is a Flat Dir repository in Gradle?  Well, its basically a directory(s) that contain a set of files that can be used to resolve dependencies.

  • Note, Gradle will assume  no transitive dependencies with this type of repo.

A good use of this repository type may be within a company that does not have its own internal repository and does not allow builds to resolve dependencies externally at build time.

So their Gradle build file might look something like this if they need to pull in specific jar versions from the lib folder at compile time.  Gradle will use the jar name from the lib folder for resolution.

repositories {
   flatdir { dir 'lib' }
}

dependencies {
   compile group: 'junit', name: 'junit', version: '4.12'
   ...
   ...
}

Now if they have a lib folder with jar files managed uniquely and they want to include all of them at compile time, then the Gradle build script might look like this.

dependencies {
   compile fileTree(include: ['*.jar'], dir: 'lib')
}

 

gradle

Ant vs Maven vs Gradle

If you are working with Java projects, then you are probably using one of the following 3 build tools.

The majority of my experience has been with Ant, which isn’t surprising since its been around the longest.  I’ve also used both Gradle and Maven for building Java projects.

Below are some of my thoughts on the benefits\draw-backs of each.  For a really detailed comparison of each tool, check out this article!

ANT 

This is my favorite build tool!  It’s probably because I am so familiar with reading Ant XML files. 🙂  I personally like working with XML files.  With Ant, there is no preconceived folder\file structure that your project needs to be in.  You have the ability to set source location properties in your Ant XML file as needed.  There are also many standard “Tasks” that you can use, along with bonus “Contrib” tasks and even “AWS” tasks.  For dependency management, you will need to use Apache Ivy in you projects build scripts.

My biggest concern with Ant is the over-all usage of the build tool is going down, which means less contributions from the community.

Ant Example – Compile Java Source (No dependency because its to much to add!!)

<project default="compile">
 <target name="compile">
  <javac srcdir="src" destdir="target"/>
 </target>
</project>

Maven

I’m a fan of Maven too!  This tool is by far the most popular of the 3.  Unlike Ant, Maven can handle both the build and dependency management itself.  One of the biggest differences from Ant is the “convention” aspect.  With Maven, your project is usually setup following the standard layout.  In a lot of ways this is good for new projects.  If you are trying to migrate an older project to Maven, this could be bad.  My suggestion with Maven is really try to understand the standard project layout before trying to use it to build your projects.

Like Ant, Maven uses XML to define the build process.  Maven XML build files are called POM.xml files.  These files assume standards and can get extremely large.

Maven Example – Compile with JUnit dependency

<project>
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.devopsunleashed.blog</groupId>
 <artifactId>search</artifactId>
 <packaging>jar</packaging>
 <version>17.3.1</version>
 <name>search</name>
 <url>http://maven.apache.org</url>
 <dependencies>
 <dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>3.8.1</version>
 <scope>test</scope>
 </dependency>
 </dependencies>
</project>

Gradle

This tool is the newest of them all and is gaining traction!  The first thing I like about Gradle is the ability to do incremental builds.  In some cases, saving 5 minutes of compile time can really add up in terms of $$$.  Another bonus is the ability to ingest Ant scripts into the Gradle build process.  Finally, like Ant, Gradle does not have to follow a standard project convention, although it does make it a lot easier!

Gradle Example – Compile with JUnit dependency using standard convention

apply plugin: 'java'

dependencies {
 testCompile 'junit:junit:4.12'
}

repositories {
 mavenCentral()
}

I will say that pulling in dependencies is pretty straight forward with Gradle!

maven

Starting my blog…..

Starting up another blog.  My previous blog was on blogspot.com and ran for about 7 years.  Lots of good stuff, but time for a change, so I decided to try wordpress.com

Some of the DevOps topics and tools I will be blogging about are.

  • DevOps
  • ELK
  • Docker
  • AWS
  • Gradle
  • Ant
  • Maven
  • Ansible
  • TFS
  • Git\GitHub
  • Jenkins
  • Java
  • Spring Boot
  • Scrum
  • Monitoring
  • etc…..