文档章节

Java Build Tools: Ant vs Maven vs Gradle

散关清渭
 散关清渭
发布于 2014/06/24 21:59
字数 814
阅读 73
收藏 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

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

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.


本文转载自:http://www.javacodegeeks.com/2014/06/java-build-tools-ant-vs-maven-vs-gradle.html

共有 人打赏支持
散关清渭
粉丝 24
博文 238
码字总数 166498
作品 0
东城
程序员
Android Gradle(一)为什么现在要用Gradle?

前言 又要开启一个新系列了,这个系列我们来学习Gradle,它是一个基于JVM的新一代构建工具,关于Gradle完全可以写一本书,这个系列会针对Android开发来对Gradle的知识进行精简讲解。Gradle目...

刘望舒
08/21
0
0
你应该更新的Java知识之构建工具:Gradle 和 Buildr

时至今日,如果你的Java项目依然需要启动一个特定的工具,比如IDE,才能编译部署,那你的项目不在本文的讨论之中,因为实在落后得太让人无语了。 好,回归正题。旧时代的Java世界,构建工具等...

苗哥
2013/07/07
0
1
Linux,maven,redis,android,java,yum,ant部署相关命令

(linux系统查看) getconf LONG_BIT 查看系统位数 (java环境变量) export JAVAHOME=/home/gcweb/usr/java/jdk1.7.045 export PATH=$JAVA_HOME/bin:$PATH 如果需要修改到系统变量中: cd ~ vi .......

shengguimin
06/26
0
0
CentOS6.8 部署Tomcat+jenkins+git+maven+ant 持续集成

CentOS6.8 部署Tomcat+jenkins+git+maven+ant 持续集成 一、环境介绍: 1、操作系统:CentOS 6.8 IP:192.168.1.100 2、JDK版本:jdk1.8.0_101 3、Tomcat版本:tomcat-9.0.0.M21 4、jenkins...

yangxuncai110
06/27
0
0
CentOS7.0 部署Tomcat+jenkins+git+maven+ant

此篇献给初学者 一、环境介绍: 1、操作系统:CentOS 7.0 IP:192.168.137.128 2、JDK版本:jdk1.8.0_101 3、Tomcat版本:tomcat-9.0.0.M21 4、jenkins版本: Jenkins ver. 2.46.3 5、git版本...

盖世英雄iii
06/27
0
0

没有更多内容

加载失败,请刷新页面

加载更多

awk命令扩展使用操作

awk 中使用外部shell变量 示例1 [root@centos01 t1022]# A=888[root@centos01 t1022]# echo "" | awk -v GET_A=$A '{print GET_A}'888[root@centos01 t1022]# echo "aaaaaaaaaaaaa" | aw......

野雪球
11分钟前
0
0
深入解析MySQL视图VIEW

Q:什么是视图?视图是干什么用的? A:视图(view)是一种虚拟存在的表,是一个逻辑表,本身并不包含数据。作为一个select语句保存在数据字典中的。   通过视图,可以展现基表的部分数据;...

IT--小哥
今天
4
0
虚拟机学习之二:垃圾收集器和内存分配策略

1.对象是否可回收 1.1引用计数算法 引用计数算法:给对象中添加一个引用计数器,每当有一个地方引用它时,计数器值就加1;当引用失效时,计数器值就减1;任何时候计数器值为0的对象就是不可能...

贾峰uk
今天
5
0
smart-doc功能使用介绍

smart-doc从8月份底开始开源发布到目前为止已经迭代了几个版本。在这里非常感谢那些敢于用smart-doc去做尝试并积极提出建议的社区用户。因此决定在本博客中重要说明下smart-doc的功能,包括使...

上官胡闹
昨天
11
0
JavaEE——Junit

声明:本栏目所使用的素材都是凯哥学堂VIP学员所写,学员有权匿名,对文章有最终解释权;凯哥学堂旨在促进VIP学员互相学习的基础上公开笔记。 Junit Junit又名单元测试,Junit是用来测试Jav...

凯哥学堂
昨天
7
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部