from ant to maven to gradle a tale of ci tools for jvm

28
From Ant to Maven to Gradle a tale of CI tools for JVM

Upload: bucharest-java-user-group

Post on 17-Feb-2017

49 views

Category:

Software


0 download

TRANSCRIPT

Page 1: From Ant to Maven to Gradle a tale of CI tools for JVM

From Ant to Maven to Gradle a tale of CI

tools for JVM

Page 2: From Ant to Maven to Gradle a tale of CI tools for JVM

Building tools History

~ 1995 BC

Page 3: From Ant to Maven to Gradle a tale of CI tools for JVM

Building tools History• 1995 - make / bash / homegrown• 2000 - Ant • 2002 – Maven 1• 2005 – Maven 2• 2009 – Maven 3• 2007 - Gradle

Page 4: From Ant to Maven to Gradle a tale of CI tools for JVM

1995 - make / bash / IDE / homegrown

Makefile Shell Script

IDE

Page 5: From Ant to Maven to Gradle a tale of CI tools for JVM

Ok ! What’s the problem ?• Non portable builds• You remember the promise write once run debug anywhere

• Non standard builds• Hard to maintain build configuration for large projects

Page 6: From Ant to Maven to Gradle a tale of CI tools for JVM

2000 - Ant FTW !Engineers are lazy so the promises of

• Portable builds• You just have to write a small file! • Like Makefile ?• Yes!• Ok !• But …

Page 7: From Ant to Maven to Gradle a tale of CI tools for JVM

Ant strength points

• ready made functions called tasks• you can group them in some groups called targets• you can write your own tasks in java• a target can depend on other targets

Page 8: From Ant to Maven to Gradle a tale of CI tools for JVM

Ant strength points• A simple ant build file

Page 9: From Ant to Maven to Gradle a tale of CI tools for JVM

Everyone was happy with

But time passed and …

Page 10: From Ant to Maven to Gradle a tale of CI tools for JVM

But time passed and …

Page 11: From Ant to Maven to Gradle a tale of CI tools for JVM

Ant weak points

• Hard to read thousands of lines of XML• Builds grow out of control• Very hard to maintain build files• No standard workflow to respect

Page 12: From Ant to Maven to Gradle a tale of CI tools for JVM

Ant weak points

• We have to create and clean up files an directories ( and we are lazy )• We have to produce, download and maintain a growing number of

libraries each with it’s own version – all by hand ( this is hard )

Page 13: From Ant to Maven to Gradle a tale of CI tools for JVM

2005 – Introducing Maven 2

• Yes I skipped Maven 1 – it was kinda experimental and Ant was the “de facto standard”

Page 14: From Ant to Maven to Gradle a tale of CI tools for JVM

Maven advantages

• Dependency management• Convention over configuration• Enforced library grouping, naming and versioning• Easier subproject management

Page 15: From Ant to Maven to Gradle a tale of CI tools for JVM

Maven advantages

• Simple more concise configuration file

Page 16: From Ant to Maven to Gradle a tale of CI tools for JVM

Maven advantagesYou just have to:

• Declare your dependencies• Put source files in src/main/java• Put test files in src/test/java• Run mvn clean install deploy• Find your artifact in target folder and optionally deployed to a server

Page 17: From Ant to Maven to Gradle a tale of CI tools for JVM

Maven disadvantagesI have a custom configuration how do I …

• Modify the project to follow the maven conventions• Find a plugin which already does that• Write a plugin to do that

Page 18: From Ant to Maven to Gradle a tale of CI tools for JVM

Maven disadvantagesBut I could wrote my own custom task in Ant

Page 19: From Ant to Maven to Gradle a tale of CI tools for JVM

Maven solutions for artifact deployment• A maven repository

• But there are other types of repositories too:• A file server (webdav, ftp, sftp, etc)• Ivy repository ( Ivy is Ant’s replica for dependency management )• P2 repository ( eclipse )

• Other reposiotories => Custom logic

Page 20: From Ant to Maven to Gradle a tale of CI tools for JVM

Maven solutions for custom logic

• Write a maven plugin• Maven ant plugin – call your ant tasks from maven• Maven groovy plugin – write groovy code and the plugin will execute

it as part of the build

Page 21: From Ant to Maven to Gradle a tale of CI tools for JVM

Introducing

Page 22: From Ant to Maven to Gradle a tale of CI tools for JVM

Gradle advantages

• Builds for: Java, C/C++, Android, Python, etc.• Best of both worlds• Convention over configuration achieved through plugins ( we can be lazy )• Flexibility through a powerful DSL ( we can do stuff in our weird ways )

Page 23: From Ant to Maven to Gradle a tale of CI tools for JVM

Gradle advantagesGradle Wrapper

• No need to install gradle – just check the ./gradlew file into your VCS and you’re good to go• the only requirement is to have java installed

• Because of ./gradlew we can be sure the build will have the exact version of gradle which is built for • useful when you have a CI server and you want to build project A with gradle

2.1 and project B with gradle 2.4

Page 24: From Ant to Maven to Gradle a tale of CI tools for JVM

Gradle advantagesGradle application plugin

• No need to concatenate all classes into a giant jar ( maven shade plugin )• The plugin will create a directory structure with • All the libraries needed • All the resources specified • A shell script to start the application

Page 25: From Ant to Maven to Gradle a tale of CI tools for JVM

Gradle DSLThe DSL is actually groovy code with some scripts added to it

• task {} – is a groovy closure so inside it you can write groovy• Why Groovy? Is a scripting language easy to use that can use all existing Java

libraries; and you can find a java library for anything

• apply plugin: java – is a call for the method apply on the Project object

Page 26: From Ant to Maven to Gradle a tale of CI tools for JVM

A simple gradle build file

Page 27: From Ant to Maven to Gradle a tale of CI tools for JVM

Demo time!

Page 28: From Ant to Maven to Gradle a tale of CI tools for JVM

Demo time!