top of page
Search

Java : Build Tools in Java

  • anithamca
  • May 5, 2021
  • 3 min read

Updated: May 7, 2021

As known , there are 3 widely used build tools in Java


Apache ANT

Apache ANT is a widely used Java based build tool from Apache Software Foundation with the full portability of the pure Java code.

An acronym for Another Neat Tool, its an XML based build tool.

Apache ANT helps you to convert source code into executable code.


Download binary from https://ant.apache.org/bindownload.cgi ,extract zip to local drive and set class path


<?xml version="1.0"?>
<project>
<target name="hello">
<echo>Hello, World</echo> </target>
</project>

Let's save this as "hellobuild.xml"

  • Goto CMD and move to the dir where you have put the hellobuild.xml

  • Now write, ant-file hellobuild.xml <target name> This should show us Hello World.


ANT Project Structure


Every build will contain three nodes:

  • Project

  • Target

  • Task

Project:

Everything inside the build file in Apache ANT is under a project tag.


Attributes:

  • Name The name of a project.

  • Basedir: This the directory from where all the paths will be calculated. This can be overridden by using "basedir" property.

  • Default: Helps you to define the default target for this project. If no target is given, then it will execute the "default."

Target

Target is a set of tasks, which is defined to get a specific state for the build process.

Attributes:

  • Name: Nate of the target (required)

  • Description: Description of the target

  • Depends: Which target this current target depend upon.

  • If: Executes the target only if a value is set for a target property

  • Unless: Executes the target if the property value is not set

Tasks

It's a piece of code which can be executed. Task have multiple argument or attributes.

The general method pattern to write task is:

<name attribute1="value" attribute2="value2"…/>

You can either use the build in a task, or you can build your own task.

Best practices of Using Apache Ant

Here, are some best practices to use Apache Ant.

  • You should automate build numbering using property files.

  • Implementing a configurable build with the help of default and build property files. These files allow you to store properties that define the data for your build process, like compiler version and optimization settings, etc.

  • You can reuse prebuilt libraries using library property files.

Maven


Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.


Download binary from https://maven.apache.org/download.cgi and follow local installation steps as required.


Maven project simple References : https://spring.io/guides/gs/maven/


Ant Vs Maven


Ant-Declarative

 <project>
    <target name="init"><tstamp/></target>
    <target name="otherTarget"   depends="init">...</target></project>

Maven-Conventional

mvn clean

Maven Vs Gradle

Reference ,


Gradle is an open-source framework for building applications and managing project dependencies, like third-party libraries.

Gradle is written in Java and GroovyDSL based on Groovy


Gradle Build Lifecycle :

Initialization > Configuration >Execution




Sample build.gradle as below,



Dag construct as below,


Gradle Tasks


gradle <task-name>

gradle build

gradle clean

gradle jar


Gradle Wrapper


The Gradle wrapper allows developers to run a specific version of Gradle, without having to install Gradle locally.

Why Gradle wrapper?

Gradle wrapper Standardizes a project on a given Gradle version, leading to more reliable and robust builds.

How do you set the Gradle version while using the Gradle wrapper?

Change the Gradle distribution version in the gradle-wrapper.properties file.

How do you set the Gradle version while using the Gradle wrapper?

Run gradlew wrapper task and pass to it the gradle version.


Reference

Advantages and core Features of Gradle that makes developers go for it ,


Gradle support for ANT and Maven.

Performance:

  1. Task output caching

  2. Incremental build

  3. Parallel execution

Gradle support multi-project builds.

Gradle wrapper.


Lets experience It!


Reference for HelloWorld Attempt : https://spring.io/guides/gs/gradle/

 
 
 

Comments


Post: Blog2_Post

Subscribe Form

Thanks for submitting!

©2021 by anitharajamuthutechno. Proudly created with Wix.com

bottom of page