A Quick Comparison of Build Tools in Java
Posted By : Navin Purohit | 29-Nov-2018
A Quick Comparison of Build tools in Java
A "Build tool" is needed to get a piece of software ready, but isn't required after that. Different programming languages have different tools: few use stalwarts like
In Java, there are mainly three build tools: Ant, Maven, and Gradle. These tools we used before the actual production environment, but are a mandatory element of the process. The main differences for these tools: usability, amount of effort, and external connections that the each has.
Let's Discuss and Differentiate each one of them in Detail:-
1. Apache Ant
Ant is an open source Java library, which helps to handle the process defined in the build file. Mainly it is used to build Java applications. Ant is very flexible, it does not force any rules like directory structure, coding conventions. Ivy is a subproject of Ant, which reacts as a dependency manager.
Price: free
Pros:
- It works well with automatic tools.
- Ant gives you almost full control
- Create custom plugins
- Rich and waste documentation.
Cons:
- XML so less customization.
- Ant makes you free to do everything yourself which is formidable.
- Difficult in understanding other projects.
- The community is old and less active.
Code Example:
[build.xml]
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="java-build-tools" default="jar"> <property name="src.dir" value="src"/> <property name="build.dir" value="build"/> <property name="classes.dir" value="${build.dir}/classes"/> <property name="jar.dir" value="${build.dir}/jar"/> <property name="lib.dir" value="lib" /> <path id="lib.path.id"> <fileset dir="${lib.dir}" /> </path> <target name="resolve"> <ivy:retrieve /> </target> <target name="clean"> <delete dir="${build.dir}"/> </target> <target name="compile" depends="resolve"> <mkdir dir="${classes.dir}"/> <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="lib.path.id"/> </target> <target name="jar" depends="compile"> <mkdir dir="${jar.dir}"/> <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}"/> </target> </project>
Run Command: ant jar
2. Apache Maven
Maven is not just a build tool. Maven even details how software is built and assist in dependency management also. Maven is used mainly for java based projects. It is well suited for large enterprises due to its very high build speed. It is better than Ant.
Price: free
Pros:
- Large ecosystem for plugins
- It makes it easy to understand other projects by providing a common structure.
- Full support for nearly any CI, IDE tool or app server.
Cons:
- Required lots of download for dependencies and plugins.
- Documentation quality.
- The community is less active.
- Weak Customization
Code Example:
[pom.xml]
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.technologyconversations</groupId> <artifactId>java-build-tools</artifactId> <packaging>jar</packaging> <version>1.0</version> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-all</artifactId> <version>1.3</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> </plugin> </plugins> </build> </project>
Run Command: mvn package
3. Gradle
Gradle is a combination of ant and maven concepts. Gradle uses groovy scripts for publishing project configuration. Gradle was developed for multi-project builds and helps incremental builds by finding which parts of the build are up-to-date.
Ant is mostly treated as legacy right now. Use of these build tools depends on the project. Sometimes we have to use a combination of Ant and Gradle, Maven and Gradle, or even three together.
Price: free
Pros:
- More customizable and streamlined tool
- No boiler plate scripts required for simpler experience
- Excellent documentation and active community
- Easily create custom plugins
Cons:
- The ecosystem for plugins is less developed.
- As a new tool, its maintenance for CI tools isn’t as developed as Maven or Ant.
Code Example:
[build.gradle]
apply plugin: 'java' apply plugin: 'checkstyle' apply plugin: 'findbugs' apply plugin: 'pmd' version = '1.0' repositories { mavenCentral() } dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3' }
Run command: gradle tasks –all
Conclusion
In this blog, we have learned about some of the most popular open source java build tools like ant, maven, and gradle. Selecting a build tool is depends on your choice and project requirement.
Reference
1. http://zeroturnaround.com/rebellabs/java-build-tools-part-1-an-introductory-crash-course-to-getting-started-with-maven-gradle-and-ant-ivy/11/
2. http://zeroturnaround.com/rebellabs/java-build-tools-part-2-a-decision-makers-comparison-of-maven-gradle-and-ant-ivy/http://
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Navin Purohit
Navin has an experience of 4 years in Java and NodeJS. He is eager to learn new technologies and want to explore his inner strengths.