Category Archives: Gradle

Gradle : Tasks


“A task is a piece of work that Gradle builds perform.”

Gradle Build script defined for one or more projects. Each project build is made up of multiple tasks. For Example:

  • Compiling classes
  • Storing classes to target
  • Copy files from resources to target.
  • Making Jar
  • Generating ]ava doc etc.

The Gradle build has common in-built tasks to build and run an application. You can also define your own tasks to customize the build process.

Topics Covered

  • Structure of Task
  • Define your Own Tasks
  • Define Default Task
  • Task Dependencies or Order
  • Use External Dependencies on Task
  • Dynamic Tasks
  • Execution of Tasks
  • Get the list of Gradle In-built tasks

Structure of Task

To define your own task in build.gradle, you need to use task keyword to define a custom task. Gradle follows this task structure :

task myTask{
   println 'Execute My Task' 
   
   doFirst{
    println 'Execute doFirst 2 with in MyTask' 
   } 
   doFirst{
    println 'Execute doFirst 1 with in MyTask' 
   }  

  doLast{
    println 'Execute doLast 1 with in MyTask' 
   } 
   doLast{
    println 'Execute doLast 2 with in MyTask' 
   }   
}

Herewith defining tasks you can also add behavior to existing tasks by implementing the actions. in the Gradle task, we can add doFirst or doLast or both actions. You will

    • doFirst: (Optional)

This action executes at the beginning of task execution.

    • doLast: (Optional)

This action executes at the end of the task execution.

doFirst and doLast can be added in task multiple times and execution of these all doFirst and doLast will be in sequence of implementation.

Output ->gradlew myTask -q

Execute My Task
Execute doFirst 1 with in MyTask
Execute doFirst 2 with in MyTask
Execute doLast 1 with in MyTask
Execute doLast 2 with in MyTask

Define Your Own Tasks

Gradle provides lots of ways to define these tasks as follows:

  1. Simple Declaration
    task myTask {
       doLast {
          println 'FacingIssuesOnIT'
       }
    }
  2. Define Task with Symbols use the symbol (<<) doLast or (>>) doFirst
    task myTask << {
       println 'FacingIssuesOnIT'
    }
  3. Alternate way with Symbol
    task (myTask) << {
       println 'FacingIssuesOnIT'
    }
  4. String Task Name
    task ('myTask') << {
       println 'FacingIssuesOnIT'
    }
  5. Define task by create() method
    tasks.create (name : 'myTask') << {
       println 'FacingIssuesOnIT'
    }

The above are ways to define tasks in Gradle. If you copy each way and try to execute a task with below command it will return the same result.

Output -> gradlew myTask -q

FacingIssuesOnIT

Define Default Task

You can define your default tasks in build.gradle file with keyword defaultTasks. These tasks will be executed when you have not specified any task for execution.

defaultTasks 'clean', 'run'

task clean {
    doLast {
        println 'Default System Cleaning!'
    }
}

task run {
    doLast {
        println 'Default Running!'
    }
}

task other {
    doLast {
        println "I am not a default task!"
    }
}

In this example mentioned default tasks as ‘clean’ and ‘run’. These tasks will execute when no task specified for execution. Let’s execute this command and see the output.
output:

Output -> gradlew -q

Default System Cleaning!
Default Running!

Output-> gradlew other -q

I am not a default task!

Task Dependencies and Order

Sometimes one task depends on other tasks and needs to define execution order of tasks. These task dependencies and task order are controlled by these methods:

  1. dependsOn: Use to add the given dependencies to this task.
    tasks.create('A')
    tasks.create('B').dependsOn('A')

    Executing B here require to execute task A first.

  2.  mustRunAfter: It defines the ordering of tasks.
    tasks.create('C')
    tasks.create('D').mustRunAfter('C')

    Execution of task D doesn’t require C but if both tasks are included for execution task C will execute first then task D.

  3.  shouldRunAfter : It’s also define ordering of tasks but not restrictive as above. This ordering ignored in two cases:
    1. If using that rule introducing a ordering cycle.
    2. If using parallel execution and all dependencies are satisfied except “should run after” then task will execute even it’s not satisfied “should run after” condition.

See Also: Gradle: Task Properties, Methods, and Actions

Example:  Here is an example to use dependsOn function to show dependencies of a task in build.gradle file.

task hello {
    doLast {
        println 'Hello!'
    }
}
task detail {
    dependsOn hello
    doLast {
        println "You are in 'Facing  Issues on IT'"
    }
}

In this example when run task detail then it’s dependent task hello will also execute.
Output

Output->gradlew detail -q

Hello!
You are in 'Facing  Issues on IT'

Note: Always define your task before use it. If not the following order you will get MissingPropertyException.

Use External Dependencies In Task

You can use buildScript function build.gradle to declare repositories and dependencies required for the task.

import org.apache.commons.codec.binary.Base64

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath group: 'commons-codec', name: 'commons-codec', version: '1.2'
    }
}

task encodeText {
    doLast {
        def byte[] encodedString = new Base64().encode('Facing Issues On IT\n'.getBytes())
        println 'Before Encode: Facing Issues on IT'
        println 'After Encodeing:' + new String(encodedString)
    }
}

In this example, for task encodeText is used Base64 class to encode text. So here you need to mentioned repositories and dependencies required to import the Base64 class

Output->gradlew encodeText -q

Before Encode: Facing Issues on IT
After Encodeing:RmFjaW5nIElzc3VlcyBPbiBJVAo=

Dynamic Tasks

By using Groovy or Kotlin scripting language, You can create tasks dynamically.

  1. Create a task by Loop
    This code will create 5 tasks by the loop (0 to 4). These task name as task0, task1, task2, task3, task4.
5.times { counter ->
    task "task$counter" {
        doLast {
            println "This is task number $counter"
        }
    }
}
task1.dependsOn task2, task3

Suppose to execute a particular task2 run command as

Output->gradlew task2 -q
This is task number 2

Output->gradle -q task1
This is task number 2
This is  task number 3
This is task number 1

Execution of Tasks

Here are different cases to execute tasks in gradle.

  • Execute Specific Task
    In all these above examples you have seen the below command to the execution of the task.

    gradlew taskName -q

    Here -q represents log level as QUIET which shows logs statement for  QUIET level and no verbose log statement. See Also : Gradle: Logging Configuration

  • Execute Default Task
    If no task specified then only default task will execute.

    gradlew  -q
  • Execute Multiple Tasks
    gradlew taskName1 taskName2 -q
  • Exclude Tasks
    Use –exclude-task to exclude tasks.

    gradlew taskName1 taskName2 --exclude-task test -q

    In this example test will not execute.

  • Execute Task in multi-Project build
    Use colon(:) to specify task related to sub project.

    gradlew mySubproject:taskName

Gradle In-built Tasks

Gradle is having a big list of in-built common tasks that not required any implementation. These can be executed by names only.

To get a list of all Gradle in-built tasks by executing the below command.

gradlew tasks --all

Here is a list of Gradle in-built tasks.

  • Build Tasks
    • assemble – Assembles the outputs of this project.
    • build – Assembles and tests this project.
    • buildDependents- Assembles and tests this project and all projects that depend on it.
    • buildNeeded – Assembles and tests this project and all projects it depends on.
    • classes – Assembles main classes
    • clean – Deletes the build directory.
    • jar – Assembles a jar archive containing the main classes
    • testClasses – Assembles test classes.
  • Build Setup Tasks
    • init – Initializes a new Gradle build.
    • wrapper – Generates Gradle wrapper files
  • Documentation tasks
    • javadoc – Generates Javadoc API documentation for the main source code.
  • Help tasks
    • buildEnvironment – Displays all buildscript dependencies declared in root project ‘GradleJavaLibrary
    • components – Displays the components produced by root project ‘GradleJavaLibrary’. [incubating]
    • dependencies – Displays all dependencies declared in root project ‘GradleJavaLibrary’.
    • dependencyInsight – Displays the insight into a specific dependency in root project ‘GradleJavaLibrary’.
    • dependentComponents – Displays the dependent components of components in root project ‘GradleJavaLibrary’. [incubating]
    • help – Displays a help message.
    • model – Displays the configuration model of root project ‘GradleJavaLibrary’. [incubating]
    • outgoingVariants – Displays the outgoing variants of root project ‘GradleJavaLibrary’.
    • projects – Displays the sub-projects of root project ‘GradleJavaLibrary’.
    • properties – Displays the properties of root project ‘GradleJavaLibrary’.
    • tasks – Displays the tasks runnable from root project ‘GradleJavaLibrary’.
  • Verification tasks
    • check – Runs all checks.
    • test – Runs the unit tests.
  • Other tasks
    • compileJava – Compiles main Java source.
    • compileTestJava – Compiles test Java source
    • prepareKotlinBuildScriptModel
    • processResources – Processes main resources.
    • processTestResources – Processes test resources.
  • Rules
    • Pattern: clean: Cleans the output files of a task.
    • Pattern: build: Assembles the artifacts of a configuration.
    • Pattern: upload: Assembles and uploads the artifacts belonging to a configuration.

References

[Solved] groovy.lang.MissingPropertyException: Could not get unknown property ‘A’ for task ‘:B’ of type org.gradle.api.DefaultTask.


groovy.lang.MissingPropertyException this exception occurred when gradle not able to find a property. Gradle check these properties in sequence as below if not find out throw this exception.

  • gradle.properties
  • System environment variables
  • command-line arguments to execute the build script
  • build.gradle

Example

Here is one example where defining two dependent tasks detail and hello. Where a detail task is dependent on hello task the same declared is by using dependsOn.

See Also: How to define Gradle tasks?

build.gradle


task detail {
    dependsOn hello
    doLast {
        println "You are in 'Facing  Issues on IT'"
    }
}

task hello {
    doLast {
        println 'Hello!'
    }
}

Exception Stackrace

Here executing Gradle task detail and using –stacktrace to print the complete stack trace of exception in the console to find out the root cause.

F:\Workspace-Gradle\MyGradleJavaProject>gradlew detail -q --stacktrace

FAILURE: Build failed with an exception.

* Where:
Build file 'F:\Workspace-Gradle\MyGradleJavaProject\build.gradle' line: 40

* What went wrong:
A problem occurred evaluating root project 'MyGradleJavaProject'.
> Could not get unknown property 'hello' for task ':detail' of type org.gradle.api.DefaultTask.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'MyGradleJavaProject'.
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:237)
        at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:77)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:242)
        at org.gradle.configuration.BuildOperationScriptPlugin$1$1.run(BuildOperationScriptPlugin.java:69)
..
...
...
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'hello' for task ':detail' of type org.gradle.api.DefaultTask.
        at org.gradle.internal.metaobject.AbstractDynamicObject.getMissingProperty(AbstractDynamicObject.java:85)
        at org.gradle.internal.metaobject.ConfigureDelegate.getProperty(ConfigureDelegate.java:130)
        at build_ys26dll53lljjzslm0aousl9$_run_closure1.doCall(F:\Workspace-Gradle\MyGradleJavaProject\build.gradle:40)
...

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

Reason of Exception

Here is the problem statement as given in cause is “Could not get unknown property ‘hello’ for task ‘:detail’ of type org.gradle.api.DefaultTask.”. It means statement dependOn hello inside the task detail not able to find task hello. Because hello task definition is after detail task and execution of the script is from Top to Down so while execution hello task not recognized and throw an exception as MissingPropertyException.

Solution

Always define your tasks before going to use it. For the above example define hello task before detail task as below.

task hello {
    doLast {
        println 'Hello!'
    }
}
task detail {
    dependsOn hello
    doLast {
        println "You are in 'Facing  Issues on IT'"
    }
}

In this example when run task detail then it’s dependent task hello will also execute.
Output

-------->gradlew detail -q

Hello!
You are in 'Facing  Issues on IT'

If this solution helps you please write comments and for any Gradle related issue post it here.

Gradle: Dependency Management


The majority of Java projects are based on libraries (jars) i.e called project dependencies. To build java projects it’s required to configure and manage dependencies.

Dependency Management

To configure a dependency in a project required this information:

  1. Which dependency you need i.e(name and version)
  2. What it’s needed for i.e (compilation or run)
  3. Where to look for it .i.e (Repository)

Here first two things need to configure in dependencies {} section while the third point will configure in repositories {} section in build.gradle.

See Also: Gradle: Repositories Configuration

repositories {
     mavenCentral()
}
dependencies {
    //use for hibernate
    implementation 'org.hibernate:hibernate-core:3.6.7.Final'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'
}

In this above example:

  • mavenCentral() is repository where gradle search for dependencies.
  • implementaion and testImplimation are scopes for dependencies which tell gradle to when these dependencies need to use.
  • junit:junit:4.12 is the ID of the dependency, In form of ‘<group>:<module>:<version>’ or ‘<groupId>:<artifactId>:<version>’ in maven terminology.

Scopes of Gradle Dependencies

Gradle provides lots of scopes to configure dependencies in projects.

Scope Description
compileOnly Use for dependencies those are required to compile your production code but that should not be part of the runtime classpath.
implementation (supersedes compile) Use for compilation and runtime.
runtimeOnly supersedes runtime) Use only at runtime, not for compilation
testCompileOnly It’s same as compileOnly for the tests
testImplementaion It’s the same as implementation for the tests.
testRuntimeOnly It’s the same as runtimeOnly for the tests.

Note: Java Library Plugin creates one more configuration – api – for dependencies that are required for compiling both modules and any modules depend on it.

Dependencies from Local File Systems

You can also set dependencies from local file system or from lib folder.

Dependencies from Project lib folder

dependencies {
    // for specific jars
    runtime files('libs/library1.jar', 'libs/library2.jar')
    //for all jars in lib folder
    runtime fileTree(dir: 'libs', include: '*.jar')
}

Dependencies from Local Machine

dependencies {
    compile fileTree(dir: "${System.properties['user.home']}/libs/banks", include: '*.jar')
}

References

https://docs.gradle.org/current/userguide/building_java_projects.html

Gradle : Repository Configuration


In Gradle, build.gradle file specifies repositories to search dependencies of projects. Gradle support repositories configuration for Ivy and Maven.

Maven Repository

You can configure maven repositories in Gradle in multiple ways:

  1. Maven Central Repository
    repositories {
        mavenCentral()
    }
  2. Maven Repository by  Target URL
    repositories {
        maven {url "http://repo.myoffice.com/maven2"}
    }
  3. Maven Repository for Other Target       For example Bintray as Maven repository
    repositories {
        maven ("http://jcenter.bintray.com/")
    }

Ivy Repository

You can also set Ivy repository as below.

repositories {
    ivy { url "http://repo.mycompany.com/repo"}
}

Dependencies from Multiple Repositories

You can add multiple dependencies at once.

repositories {
   maven ("https://repository-engine.forge.cloudbees.com/snapshot/")
   jcenter {
      url "http://jcenter.bintray.com/"
   }
}

Now you have learned about the ways to configure Gradle repositories in build.gradle file to search dependencies. In case if you want to use dependencies from your local file system you can figure that also in the dependencies section. Check Gradle: Dependencies Configuration to know more about it.

Gradle : Logging Configuration


Gradle is very rich with logging configuration options for log level, formatting and error stacktrace handling etc.

Gradle logging configuration is required to debug build failure, task execution status and sequence of execution of tasks to build and run projects. It’s formatting style and colors highlight option make build failure debugging easy to understand and resolve issues.

Topics Covered

  • Gradle Log Level Configuration
  • Write Your Own Log Message
  • Gradle Stacktrace Options
  • Gradle Console Log Formatting
  • Gradle Warning Display Options

Gradle Log Level Configuration

Gradle support following log level options, It ordered from least verbose (–debug) to most most verbose (–quiet). Gradle default log level is Lifecycle.

Options Description
-q , –quiet Set Gradle log level QUIET to print errors only.
-w , –warn Set Gradle log level WARN to print warnings and errors.
-i , –info Set Gradle log level INFO to print info, warning and errors.
-d , –debug Set Gradle log level DEBUG to print debug, info, warning and errors.
No Log Option Default log level LIFECYCLE once you not set any. It prints gradle life cycle all statements to execute a task..

There are multiple ways to set Gradle Log Level based on your need:

Set property in gradle.properties in your project root folder or in you GRADLE_HOME folder.

org.gradle.logging.level=debug

or Set Gradle environment variable.

-Dorg.gradle.logging.level=debug

or Pass Gradle log level option on time of execution of tasks. For Example: Passing log level as -w to print logs for warning or errors.

gradlew [task]-w

For Example:

Now takes reference of previous, Gradle Multi Project Application and execute gradle build with out any log level (Default log level is LIFECYCLE)  and builds got executed successfully but not printed any task execution steps.

Gradle multi project build after include sub project

I will take reference of same example for further log settings.

Write Your Own Log Messages

Gradle supports many ways to write your own Log messages in build.gradle file.

  1. Write Log Message by stdout: By default logged these message at QUIET level.
    println 'Logged message at QUIET level'
    
  2. Write Log Message by Logger property: Gradle provide logger property to write message on different log level.
    logger.quiet('Always Logged an info log message.')
    logger.error('Logged an error message.')
    logger.warn('Logged  a warning message.')
    logger.lifecycle('Logged  a lifecycle info message.')
    logger.info('Logged an info message.')
    logger.debug('Logged a debug message.')
    logger.trace('Logged a trace message.')
    
  3.  Write Log Message with place holder: Use curly braces ({}) for place holder.
    logger.info('Test a place holder {} log message', 'info')
    

Now for test your log level configuration. Write these state debug statements in your build.gradle file.

//top level log stdout
println 'Logged message at QUIET level'
 
task logInfo {
    //task debug
    logger.quiet('Always Logged an info log message.')
    logger.error('Logged an error message.')
    logger.warn('Logged  a warning message.')
    logger.lifecycle('Logged  a lifecycle info message.')
    logger.info('Logged an info message.')
    logger.debug('Logged a debug message.')
    logger.trace('Logged a trace message.')
    
    //test place holder
    logger.info('Test a place holder {} log message', 'info')
}

Run these command on console and verify your results.

Gradle Log Level

In above example, running specific logInfo task to check our configuration. Based on passing log level option it’s showing log statements in console.

Gradle Stacktrace Options

By default Gradle doesn’t print stacktrace in logs if case build get fail. To enable stacktrace use these options.

Options Description
-s or –stacktrace Use this option when need to get truncated stacktrace. It reduces the unnecessary verbose statements.
-S or –full-stacktrace Use this option when need print complete stacktrace and it’s also print stacktrace for deprecated warnings.

Gradle Console Log Formatting

Gradle is rich with console log formatting.  Gradle console mode provide some additional features while build and run:

  • Use colors and fonts to highlight log level, important outputs and errors.
  • Show Progress lines and what execution is going currently.
  • Progress bar and timer describe the overall execution status.
Options Description
plain This option disable all color and rich output in console log output. This is consider as default option when Gradle not attached to a terminal.
auto This is default option to enable color and other rich output when attached to a terminal.
rich This provide rich output in form of color, fonts and also support ANSI control characters.
verbose It’s use to enable color and other rich output like the rich, but print task names and out comes at the lifecycle log level.

There are multiple ways to set Gradle console log formatting options as below:

Set property in gradle.properties in your project root folder or in you GRADLE_HOME folder.

org.gradle.console=plain

or Set as system environment variable from command prompt.

-Dorg.gradle.console=plain

To pass Gradle console log  option on time of execution of tasks. For Example :Here by default log level is ‘–lifecycle’  and set console log option as plain (‘–console=plain’) to print logs console..

gradlew [task]--console=plain

Now build same previous, Gradle Multi Project Application with console option as ‘–console=plain’ and see the difference it’s printing all steps followed for execution of tasks.

Multi project all task in console

As an assignment you can try below line of statements to test different log level and see console outputs.

//Log Level as debubg
gradlew [task] -d --console=plain
//Log Level as info
gradlew [task]-i --console=plain

Gradle Warnings Display Options

Gradle doesn’t show warnings (e.g deprecated warnings) in sequence . Gradle collects all warnings and show a summary at end of builds:

For Example

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.

Gradle provides these options to show/ hide warnings in console log.

Options Description
all To log all warnings.
fail To log all warnings and fails in build.
summary To log summary suppress all warnings at end of build.
none To suppress all warnings and summary at end of build.

Gradle provides multiple ways to set property to show/hide gradle warnings:

Set property in gradle.properties in your project root folder or in you GRADLE_HOME folder.

org.gradle.warning.mode=all

or Set property as gradle environment variable.

-Dorg.gradle.warning.mode=all

or Pass warning mode on time on execution of task.

gradlew [task] --warning-mode=all

Conclusion

Here you have learn about gradle log level  configuration on project , tasks and centralize level. Here are these options:

  • Gradle Log Level:  Use these  different log level to debug gradle build.
    org.gradle.logging.level=debug|info|warn|quit
    
  • Gradle Stacktrace Options: Use -s for truncated stacktrace and -S for full stacktrace.
  • Gradle Console Log Formatting: For  formatted colored logs and  get execution progress status use  these console log options.
    org.gradle.console=plain|auto|rich|verbose
    
  • Gradle Warning show/hide: Use these  options for show and hide warnings.
    org.gradle.warning.mode=all|fail|summary|none
    

Gradle: Plugin Configuration in Eclipse or STS


Gradle Configuration in Eclipse or STS (Spring Tool Suite)

  • Step 1: Open Eclipse or STS IDE
  • Step 2: Go to Help -> Install from Market Place.
  • Step 3: Search for Gradle
  • Step 4: Select the option “Buildship Gradle Integration “.
  • Step 5: Click on the Installation button as in the below screen.

    Gradle Plugin Configugration in Eclipse or STS

  • Step 6: Navigate to the next screen. Select “I accept terms and license agreements
  • Step 7: Click on the Finish button.
  • Step 8: Click on Confirm and then your IDE will get started.
  • Step 9: Go to File -> Projects -> Search for Gradle.
  • Step 10: You will see the below screen.

Gradle Project in Eclipse

Here you have learned about the configuration of the Gradle plugin in Eclipse and STS (Spring Tool Suite).

See Also:

If this blog helps you or any issue facing related to Gradle drop comments to us.

Gradle : Installation On Linux and Mac


Gradle can be installed on an and run on any  Operating System and it required JDK and JRE installed on your machine.

Gradle Current Version: Gradle 6.3

Gradle Pre-Requisites

Your machine should have Java 8 or later versions of it.

java -version

if Java 8 is not installed and configured follow these steps in link: How to set java path of JDK/JRE?

Gradle Installation On Linux or Mac

  •  Download the latest Gradle Binary distribution for Linux  or Mac OS from this link: https://gradle.org/releases/
  •  Create a Gradle folder and unpack the zip file in this folder
    $ mkdir /opt/Gradle
    $ unzip -d /opt/Gradle gradle-6.3-bin.zip
    $ ls /opt/Gradle/gradle-6.3
    LICENSE  NOTICE  bin  getting-started.html  init.d  lib  media
  • Configure Your System Environment: Set PATH environment variable to include bin directory of unzipped Gradle.
    $ export PATH=$PATH:/opt/Gradle/gradle-6.3/bin
  •  Verify the Gradle installation and configuration by running below the Gradle command in the console.
    gradle -v
    ------------------------------------------------------------
    Gradle 6.3
    ------------------------------------------------------------

Here you have learned about Gradle installation and configuration in Linux and Mac OS. If you are facing any Gradle issue share your comments.

References

Gradle : Installation On Windows


Gradle can be installed on an and run on any  Operating System and it required JDK and JRE installed on your machine.

Gradle Current Version: Gradle 6.3

Gradle Pre-Requisites

Your machine should have Java 8 or later versions of it.

java -version

Java Version

if Java 8 is not installed and configured follow these steps in link: How to set java path of JDK/JRE?

Gradle Installation on Windows

  •  Download the latest Gradle Binary distribution from this link: https://gradle.org/releases/
  •  Unzip the downloaded zip file.
  • Create a folder like C:/Gradle and copy the unzipped folder in this location.
  • Set path environment variable for Gradle by using these steps:  Go to File Explorer -> right-click on This PC or (My Computer) icon -> click on Properties -> Advance System Settings ->Environment Variables.  Under System variable, select path property and then click on the edit button, then append this path C:\Gradle\gradle-6.3\bin as below and save it.Gradle Installation and Configuration in Windows
  •  Verify the Gradle installation and configuration by running below the Gradle command in the console.
    gradle -v

    Gradle Version

Here you have learned about Gradle installation and configuration in windows. If you are facing any Gradle issue share your comments.

References

Gradle Overview


“Gradle is advanced, open-source, a general-purpose build automation system that built over ANT, Ivy and Maven repositories”.

Points to Remember

  • Gradle initial version introduced in 2007.
  • Gradle stable current release 6.3 on March 24, 2020
  • Gradle official website https://gradle.org/
  • Gradle API is designed using Groovy Language specifically for Java projects.
  • Gradle supports groovy based DSL (Domain Specific Language) over XML.
  • Gradle is a solution to resolve the dependency management issue of Maven.

See Also:

Features of Gradle

Gradle provides the following features:

  • Open source: Gradle is a free open source project, licensed under the ASL (Apache Software License).
  • Groovy: Gradle’s build script and API are written in Groovy. Gradle is designed towards being used as a language, not as a rigid framework.
  • Language for dependency-based programming: Gradle provides a declarative language for a general-purpose task graph, which you can be leverage in your build.
  • Gradle API: These APIs allows to monitor, customize configuration and execution behavior to its core functionality
  • Declarative builds: Gradle is Domain Specific Language (DSL) based on Groovy language. It provides a declarative language element that provides build-by-convention support for Java, OSGI, Groovy, Scala OSGI, and Web.
  • Structure your build: Gradle allows implement common design principles which will give a well-structured and easily maintained comprehensible build.
  • Gradle Wrapper: It is useful for the continuous integration of servers and helps to execute Gradle builds on machines where Gradle is not installed.
  • Gradle scales: Gradle is easily capable of making builds for a single project to enterprise application of multiple projects.
  • Multi-Project Builds: Gradle is capable of doing multi-project builds and supports partial builds also. If you build a project Gradle takes care of building all dependent subprojects.
  • Gradle is the first build integration tool: Gradle fully supported for ANT tasks, Maven and lvy repository for publishing and retrieving dependencies. Gradle provides a converter for Maven pom.xml to the Gradle script.
  • Ease of migration: Gradle can easily adapt to any structure Therefore you can always develop your Gradle build script in the same branch where you want to build.

 

Maven Vs Gradle


Gradle is a built tool developed over Maven and Ant. It’s having lots of differences when compared with Maven.

See Also:

Maven Gradle
Maven uses XML Gradle doesn’t use XML
Maven written in Java Gradle written in Java, Kotlin and Gradle
Maven scripts are not shorter and clean Gradle Scripts are shorter and clean
Maven is a software project management and builds tool developed for Java-based applications. Gradle is an open-source, build automation system built on concepts of maven and ant.
Maven makes build process easier, provides best guidelines for development and allow to migrate new features Gradle allows structuring of build and supports for multi projects builds. Gradle increases productivity provides ways to migrate and builds applications.