Java Build Tools: Ant vs Maven vs Gradle

发布于 2014/06/24 21:59
字数 814
阅读 71
收藏 0
点赞 0
评论 0

Ant with Ivy

Ant was the first among “modern” build tools. In many aspects it is similar to Make. It was released in 2000 and in a short period of time became the most popular build tool for Java projects. It has very low learning curve thus allowing anyone to start using it without any special preparation. It is based on procedural programming idea.

After its initial release, it was improved with the ability to accept plug-ins.

Major drawback was XML as the format to write build scripts. XML, being hierarchical in nature, is not a good fit for procedural programming approach Ant uses. Another problem with Ant is that its XML tends to become unmanageably big when used with all but very small projects.

Later on, as dependency management over the network became a must, Ant adopted Apache Ivy.

Main benefit of Ant is its control of the build process.


Maven was released in 2004. Its goal was to improve upon some of the problems developers were facing when using Ant.

Maven continues using XML as the format to write build specification. However, structure is diametrically different. While Ant requires developers to write all the commands that lead to the successful execution of some task, Maven relies on conventions and provides the available targets (goals) that can be invoked. As the additional, and probably most important addition, Maven introduced the ability to download dependencies over the network (later on adopted by Ant through Ivy). That in itself revolutionized the way we deliver software.

However, Maven has its own problems. Dependencies management does not handle well conflicts between different versions of the same library (something Ivy is much better at). XML as the build configuration format is strictly structured and highly standardized. Customization of targets (goals) is hard. Since Maven is focused mostly on dependency management, complex, customized build scripts are actually harder to write in Maven than in Ant.

Maven configuration written in XML continuous being big and cumbersome. On bigger projects it can have hundreds of lines of code without actually doing anything “extraordinary”.

Main benefit from Maven is its life-cycle. As long as the project is based on certain standards, with Maven one can pass through the whole life cycle with relative ease. This comes at a cost of flexibility.

In the mean time the interest for DSLs (Domain Specific Languages) continued increasing. The idea is to have languages designed to solve problems belonging to a specific domain. In case of builds, one of the results of applying DSL is Gradle.


Gradle combines good parts of both tools and builds on top of them with DSL and other improvements. It has Ant’s power and flexibility with Maven’s life-cycle and ease of use. The end result is a tool that was released in 2012 and gained a lot of attention in a short period of time. For example, Google adopted Gradle as the default build tool for the Android OS.

Gradle does not use XML. Instead, it had its own DSL based on Groovy (one of JVM languages). As a result, Gradle build scripts tend to be much shorter and clearer than those written for Ant or Maven. The amount of boilerplate code is much smaller with Gradle since its DSL is designed to solve a specific problem: move software through its life cycle, from compilation through static analysis and testing until packaging and deployment.

It is using Apache Ivy for JAR dependencies.

Gradle effort can be summed as “convention is good and so is flexibility”.

Code examples

We’ll create build scripts that will compile, perform static analysis, run unit tests and, finally, create JAR files. We’ll do those operations in all three frameworks (Ant, Maven and Gradle) and compare the syntax. By comparing the code for each task we’ll be able to get a better understanding of the differences and make an informed decision regarding the choice of the build tool.

First things first. If you’ll do the examples from this article by yourself, you’ll need AntIvyMaven and Gradle installed. Please follow installation instructions provided by makers of those tools. You can choose not to run examples by yourself and skip the installation altogether. Code snippets should be enough to give you the basic idea of how each of the tools work.

Code repository https://github.com/vfarcic/JavaBuildTools contains the java code (two simple classes with corresponding tests), checkstyle configuration and Ant, Ivy, Maven and Gradle configuration files.

Let’s start with Ant and Ivy.

© 著作权归作者所有

共有 人打赏支持
粉丝 24
博文 159
码字总数 166498
作品 0
build.xml: 33: Class not found: javac1.8的解决办法

build.xml: 33: Class not found: javac1.8的解决办法 第一步:错误信息如下: BUILD FAILED C:UsersDavideclipsetest-projectbuild.xml:33: Class not found: javac1.8 第二步:错误分析: ......

挑战者666888 ⋅ 05/23 ⋅ 0


Andrid多分包技术在大型项目编译方面起着至关重要的作用,作为一个高级开发者我们有必要掌握此技能,现在我带领大家统一学习此项技能,并教会大家分别使用Ant和Gradle构建。 什么是Dex Dex是...

tan6458 ⋅ 2017/01/09 ⋅ 0


什么是Jenkins? jenkins是一个广泛用于持续构建的可视化web工具,持续构建说得更直白点,就是各种项目的"自动化"编译、打包、分发部署。jenkins可以很好的支持各种语言(比如:java, c#, php...

IT人故事会 ⋅ 05/03 ⋅ 0

Java GUI实用小工具集 - Common Gui Tools

Common Gui Tools 是用java编写,GUI界面的实用小工具集,1.4版有20个小工具: 1,编码转换:Character Converter 2,加密解密:Encrypt And Decrypt 3,计算文件数字签名:File Digital Si...

bs2004 ⋅ 2013/03/20 ⋅ 3

Common Gui Tools 1.4 发布,Java GUI 实用小工具集

Java GUI实用小工具集 Common Gui Tools 新增:二维码生成解析、时间戳转换、Json格式化、文本文件切分等。 Common Gui Tools 是用java编写,GUI界面的实用小工具集,1.4版有20个小工具: 1,...

bs2004 ⋅ 04/22 ⋅ 0

JSF 标准的开源实现 Mojarra 已转移至 Eclipse 基金会

Mojarra 项目负责人 Arjan Tijms 在邮件中宣布,Mojarra 项目已成功转移到了 Eclipse EE4J,代码托管在 GitHub 上(https://github.com/eclipse-ee4j/mojarra)。 Mojarra 目前的版本被设置为 ...

局长 ⋅ 04/20 ⋅ 0

Gradle 4.7 正式版发布,支持 JDK 10

Gradle 4.7 正式版发布。Gradle 是一个基于 Apache Ant 和 Apache Maven 概念的项目自动化构建工具,支持依赖管理和多项目,类似 Maven,但比之简单轻便。它使用一种基于 Groovy 的特定领域语...

周其 ⋅ 04/20 ⋅ 0


前言: 关于.jar文件: 平时我们Android项目开发中经常会用到第三方的.jar文件。 其实.jar文件就是一个类似.zip文件的压缩包,里面包含了一些源代码,注意的是.jar不包含资源文件(res、图片...

听着music睡 ⋅ 2016/09/21 ⋅ 0

在线集成开发环境 - Eclipse Che

Eclipse Che 是一个高性能的基于浏览器的集成开发环境,通过提供结构化的工作区、项目输入、模块化扩展插件来支持 Codenvy 的引擎。Eclipse Che 采用 Java 开发,支持 Windows、Linux 和 OS...

匿名 ⋅ 2015/12/08 ⋅ 43

JavaFX 已从 JDK 中独立拆分,早期预览版开放下载

今年 3 月,我们曾报道过 Oracle 从 JDK 11 开始将把 JavaFX 将作为独立模块从 JDK 中分离出来,以使 JavaFX 更易于被采用的消息。近日,Oracle 在邮件列表上宣布,独立的 JavaFX SDK 早期预...

王练 ⋅ 05/10 ⋅ 4





Centos7重置Mysql 8.0.1 root 密码

问题产生背景: 安装完 最新版的 mysql8.0.1后忘记了密码,向重置root密码;找了网上好多资料都不尽相同,根据自己的问题总结如下: 第一步:修改配置文件免密码登录mysql vim /etc/my.cnf 1...

豆花饭烧土豆 ⋅ 57分钟前 ⋅ 0



原创小博客 ⋅ 今天 ⋅ 0


LVM LVM就是动态卷管理,可以将多个硬盘和硬盘分区做成一个逻辑卷,并把这个逻辑卷作为一个整体来统一管理,动态对分区进行扩缩空间大小,安全快捷方便管理。 1.新建分区,更改类型为8e 即L...

蛋黄Yolks ⋅ 今天 ⋅ 0

Hadoop Yarn调度器的选择和使用

一、引言 Yarn在Hadoop的生态系统中担任了资源管理和任务调度的角色。在讨论其构造器之前先简单了解一下Yarn的架构。 上图是Yarn的基本架构,其中ResourceManager是整个架构的核心组件,它负...

p柯西 ⋅ 今天 ⋅ 0

uWSGI + Django @ Ubuntu

创建 Django App Project 创建后, 可以看到路径下有一个wsgi.py的问题 uWSGI运行 直接命令行运行 利用如下命令, 可直接访问 uwsgi --http :8080 --wsgi-file dj/wsgi.py 配置文件 & 运行 [u...

袁祾 ⋅ 今天 ⋅ 0


在JVM中,我们经常提到的就是堆了,堆确实很重要,其实,除了堆之外,还有几个重要的模块,看下图: 大 多数情况下,我们并不需要关心JVM的底层,但是如果了解它的话,对于我们系统调优是非常...

不羁之后 ⋅ 昨天 ⋅ 0

推荐:并发情况下:Java HashMap 形成死循环的原因

在淘宝内网里看到同事发了贴说了一个CPU被100%的线上故障,并且这个事发生了很多次,原因是在Java语言在并发情况下使用HashMap造成Race Condition,从而导致死循环。这个事情我4、5年前也经历...

码代码的小司机 ⋅ 昨天 ⋅ 2

聊聊spring cloud gateway的RetryGatewayFilter

序 本文主要研究一下spring cloud gateway的RetryGatewayFilter GatewayAutoConfiguration spring-cloud-gateway-core-2.0.0.RC2-sources.jar!/org/springframework/cloud/gateway/config/G......

go4it ⋅ 昨天 ⋅ 0


导读 MySQL是一个开源数据库管理软件,可帮助用户存储,组织和以后检索数据。 它有多种选项来授予特定用户在表和数据库中的细微的权限 - 本教程将简要介绍一些选项。 如何创建新用户 在MySQL...

问题终结者 ⋅ 昨天 ⋅ 0

android -------- 颜色的半透明效果配置

最近有朋友问我 Android 背景颜色的半透明效果配置,我网上看资料,总结了一下, 开发中也是常常遇到的,所以来写篇博客 常用的颜色值格式有: RGB ARGB RRGGBB AARRGGBB 这4种 透明度 透明度...

切切歆语 ⋅ 昨天 ⋅ 0