Start Here !

Welcome to my website. Find articles, presentations, tutorials, experiments on various technologies.

You can get in touch with me anytime at

r o m i n . i r a n i @ m i n d s t o r m s o f t w a r e . c o m

I am also active on Twitter – do follow me.

Posted in Uncategorized | Leave a comment

Gradle Tutorial : Part 1 : Installation + Setup

To read an overview of this series, refer to the original blog post.

In this part of the tutorial, we shall focus on setting up Gradle on our system. While tools like Android Studio do ship with an internal Gradle distribution, our intention here is to understand the tools, its installation, the setup and firing up some basic Gradle commands.

Before we begin with that, if you are still wondering why Gradle is a good choice for build tools, I suggest that you read the following article. Though not essential to read it, it opens up your views as to why companies/developers are flocking to Gradle.

The next few sections will take you through setting up of Gradle on your machine. Gradle requires Java to be present on your machine. So, I shall assume that you are a Java developer and have setup the Java SDK on your machine. 

Download Gradle

At the time of writing, Gradle is in version 2.0 and is available for download here.

Just go ahead and download the ZIP file to your machine. You should have a file named gradle-2.0-all.zip. Expand it to a folder of your choice.

For e.g. on my machine, I have expanded the same in e:\gradle-2.0, such that I have the following sub-folders as shown below:

img3

Environment Settings

The \bin folder of your gradle distribution contains the gradle script file (both Unix and Windows) that you will use to run the gradle command along with various parameters.

Ideally, do the following:

  1. Create an environment variable GRADLE_HOME and point it to the Gradle Installation folder. On my machine, the Gradle installation folder is e:\gradle-2.0 and hence I have created a GRADLE_HOME Environment variable that has the value e:\gradle-2.0
  2. Add %GRADLE_HOME%\bin to the PATH environment variable. This will allow you to launch gradle command from any directory.

Verify Gradle Setup

To verify our setup, go to the command prompt / terminal and type the following:

gradle -v

This should display information about Gradle / versions and other information as shown below:

------------------------------------------------------------
Gradle 2.0
------------------------------------------------------------
Build time: 2014-07-01 07:45:34 UTC
Build number: none
Revision: b6ead6fa452dfdadec484059191eb641d817226c
Groovy: 2.3.3
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_40 (Oracle Corporation 24.0-b56)
OS: Windows 7 6.1 amd64

If you do not see information similar to the one above, check your installation of Gradle and ensure that you have set your PATH variable correctly that contains the direct %GRADLE_HOME%\bin as explained earlier.

A word about Groovy

Any discussion of Gradle is incomplete without Groovy. Groovy as you know is one of the most popular and powerful languages available on the JVM.

Some of the key reasons in favor of Gradle are:

  • It is less verbose
  • It is very flexible
  • It lets you configure and dictate things the way you want

Groovy plays a big role in making the above points happen. Unlike XML that is typically used in Ant and Maven, Groovy is a high level language that not only cuts down on the verbosity with its intuitive and productive syntax but it also gives you full programmatic power to tweak / specify things. All programming language advances like closures etc are available to you. And the build file that you typically ask Gradle to run is actually code that is running for you.

So, while you do not have to know Groovy well to understand Gravel, it helps to know that the full power of Groovy is available to you, should you desire that.

Groovy is shipped with default with your Gradle distribution, so you do not have to separately download the same. 

Basic Gradle commands

We have not yet written any source code or build files (Gradle) and we will get to it in while. But try out the following on the command line:

gradle -q help

This command prints out basic help information for Gradle. The -q parameter is just for quiet mode in the console output. It is quite useful as you move along to see less verbose output.

gradle -q tasks

This shows a list of tasks that are already available to you. Give it a shot.

gradle properties

This will list of several properties that are preconfigured for you. You can definitely modify most of these properties in your build files. But it gives you a sense to the heavy duty work that Gradle is setting up for you prior to executing your tasks.

We are not yet going to get to compiling our Java code projects, etc. That is for the next part in this series. We are going to understand how Groovy brings the whole power of programming to Gradle.

To get started, let us first talk about the build.gradle file. This is the standard name used for our build file. All instructions that you need to give to Gradle are contained over here. Over the entire series, we will essentially work with build.gradle file to create / use all sorts of plugins/tasks that will help us compile, build , test and run our Java applications.

For now, let us try out the following (I leave it to you to use a directory of your choice to store the files/code as we move along):

In a folder of your choice, for e.g. example1, create a file named build.gradle.

Put the following as contents of the build.gradle file.

task compileTask << { 
    System.out.println "compiling..." 
}

Now, go to the command line and the folder in which you created the above build.gradle and give the following command

gradle -q tasks

This will list out various tasks that you can perform and you will notice in the output that apart from the standard tasks that you noticed, you also have the task that we created i.e. compileTask 

Other tasks
-----------
compileTask

This brings us to the first concept that our gradle build file is a series of tasks that we specify and which the gradle build system can execute for us. Currently the task that we have specified is named compileTask and what you see is the Groovy code where we just define the task code, where all we are doing is just doing a System.out.println. Remember that Groovy is a high level JVM language.

Now, what if we want to run the compileTask command ?

Before, we get to that, there is one more point to understand. When we fire the gradle command, it looks for a file named build.gradle in the current directory. If it finds one, it uses that. In the above case, since it found one, it determined what tasks are present in the file and added that to the list of tasks that it can perform.

So, what happens if we just type gradle with no other parameters nor do we specify any task to be execute. Let’s try that:

gradle

This will give the following output:

:help
Welcome to Gradle 2.0.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
BUILD SUCCESSFUL
Total time: 2.39 secs

It is clearly telling you that you need to specify the task name when you run it i.e. gradle <task>. Let us do that by giving the following command:

gradle -q compileTask

This will output the text

compiling...

Let us enhance the build.gradle file with another task, so that it looks now like the following:

task compileTask << {
 System.out.println "compiling..." 
}

task buildTask << {
 System.out.println "building..."
}

Now, if you give the following command:

gradle -q tasks

You will find that both the tasks are listed in the otherTasks as shown below:

Other tasks
-----------
buildTask
compileTask

You can now run any of the tasks via gradle compileTask or gradle buildTask and so on.

What if we want to create a default task to be executed, so that if we do not specify the task name, it should execute that.

To do that, modify the build.gradle file as shown below:

defaultTasks 'buildTask'

task compileTask << {
  System.out.println "compiling..." 
}

task buildTask << {
  System.out.println "building..."
}

Now, if we simply say gradle -q , it will print the building… string output.

The last part to note here is dependency among tasks. What if we want to make the buildTask dependent on the compileTask, so that if the buildTask is run, it should always run the compileTask first.

To do that, modify the build.gradle file as shown below:

defaultTasks 'buildTask'

task compileTask << {
  System.out.println "compiling..." 
}

task buildTask (dependsOn:compileTask) << {
  System.out.println "building..."
}

Now, when you simply invoke gradle -q , it will show the following output:

compiling...
building...

What we have covered in this episode is the very basics of Gradle. Think of your build file as a series of tasks that need to be done. If you are a Java developer and have some experience of the build process (Ant, Maven) , you can easily relate to the fact that to build any stuff, we will need to do things like: compile, build, run tests, package , etc. These are nothing but tasks in Gradle.

We do not necessary have to write all these tasks by hand, though you could if you want to. By using convention that Gradle follows and plugins that work automagically off those conventions, we can perform the same series of steps that are required to build our projects.

There are plugins available in Gradle for e.g. Java plugin, WAR plugin, AppEngine plugin, Android plugin and so on, that expose predefined tasks that you can invoke. We shall see more of that, moving forward in this series.

Next Part

In the next part of the tutorial, we shall look at using Gradle to compile / build our Java projects.

Posted in Tools | 1 Comment

Announcing .. Gradle Tutorial Series

img2

Welcome to a new blog series where I aim to cover the basics of Gradle, the build tool that not just everyone is talking about but adopting widely. Companies, small and large have adopted this tool and while you might be familiar with Ant and Maven, it is time to take a look at Gradle.

The need for writing this series has come about primarily due to my work with a few Google related technologies/frameworks. I use the Google Cloud Platform widely for my projects (both professional and hobby) and have primarily used Eclipse as my IDE for both Cloud Projects (running on Google App Engine) and front-end mobile applications (Android). With Google putting its weight behind Android Studio, one of the things that hit me immediately when I try to use Android Studio was the fact that it used Gradle as its build tool.

My first experience with Android Studio and Gradle was one that cannot be described. I do not want to digress from the topic at hand, but let’s say that it was a difficult time to understand the exceptions, what Gradle is doing in the background and how to correctly set up dependencies of already existing projects. If you have been trying to play with Gradle, you know exactly what I mean. This series is my attempt to explain just about enough of Gradle so that you can get going with minimum fuss and save loads of time. In fact, I am confident that the more you use Gradle, the more you will appreciate the reasons for using it and which was not very apparent to me, the first time I experienced all those problems.

The series will be more task focused with just enough explanation for you to understand what is going on behind the scenes. I will spend less time on marketing Gradle and going deep into reasons on why it works in a certain way. I will reference articles at the right places for those who wish to take a deeper dive. For the rest of us, who are interested in using Android Studio + Google Cloud Platform , we want to be as comfortable with the toolset, so that we can continue to build great applications and let Gradle do the heavy work of the mechanics that eventually result in binaries that we can give to the world.

This tutorial series will take you to a journey that covers the following:

  • Part 1 : Installation of Gradle and setting it up correctly on your system
  • Part 2 : Your first Java Project Build with Gradle
  • Part 3 : Java Web Applications with Gradle
  • Part 4 : App Engine Gradle Plugin
  • Part 5 : Android Studio : Multi-Module Project builds with Gradle (This includes a Project that contains App Engine backends – Cloudpoints, Android App, Wear App, etc)

Some of these parts could go over into multiple parts, but at a high level, this is what I plan to cover. If you notice, the first 3 parts will focus on Gradle basics without getting into any specific Google stuff ( Google App Engine , Android, Android Studio IDE, etc).

To all Java Developers out there, lets rock the Gradle !

 

Posted in Tools | 1 Comment

Once Upon a Time in India : #1 – Khaled and his Didi song

Part of “Once Upon a Time in India Series“: 

The musician Cheb Khaled must have got the shock of his life and maybe he has still not recovered when his song titled “Didi” captured India in the 90s (1993-1994).  It fast became a song that got the crowd into a frenzy at any joyous gathering of people. And best of all, people who started dancing to this song were not even drunk at times. I also believe (could be wrong) that 99.99% of us did not understand even one word of what he was trying to say and could only pronounce “Didi”. Maybe that was the essence, all you had to do was just say “Didi” at some intervals in the song and  you were in !

It showed music had universal appeal and it surely adds to the confusion in the minds of everyone about “what succeeds in India”.

Anyways, enjoy the song :

Do give your comments on what you think should appear in this series. You will be credited for it. The essence of this series is captured here, so please read that.

P.S: The # in the title is just a number, not a ranking.

Posted in Personal | Leave a comment

New Series titled “Once Upon a Time in India”

As you grow older, you look back at some event or the other that happened across India, which is where I was born, brought up and live. These events typically captured the imagination of the nation and while they their influence was short-lived (typically), the hysteria that it generated was tremendous.

It is with that spirit, that I wish to capture some event and chronicle it .. well .. just for the sake of it. This event could be some sporting thing, or a music video, or a cartoon, or some comment / dialogue, a film, a song, a new technology .. almost anything.

jif_2009

You can write to me in the comments on whatever you believe caught our fancy .. and I hope to target those events for which we have some online content that can be linked to, so that the readers can relive and of course enjoy that moment. Ideally I am looking for something that has occurred in the 80s and 90s but still feel free to note and let me know otherwise. I will credit you with the link, if I publish it.

I do not promise the frequency at which this series will post stuff but it should help chronicle some key incidents.

The order of publication will be completely random and in no order of significance or craziness that it caused. I am also not interested in any political/terrorist/religious activity that caused suffering/pain and divisions. 

Maybe someone has already thought of such a series and it is there on the web (in fact it should be!) but still I don’t care. In the spirit of “Let’s do this”… we move forward.

So, sit back and enjoy.

Photo Credits : http://jaxindiafest.org/mission

 

Posted in Personal | 3 Comments

Book Review : Raspberry Pi Server Essentials

This is a book review for Packt Publishing‘s Raspberry Pi Server Essentials.

packt-rpi-server

Raspberry Pi is often touted as a boon for classroom computing. I have often seen scenarios where several folks have purchased a Raspberry Pi and after a few sessions with it have not utilized it much. Well sure the hobbyists are busy building sensor networks but most people need to understand how to employ their Pi for tasks that are likely to be more useful to them, in and around their computing needs.

This is where “Raspberry Pi Server Essentials” book comes in. It contains several chapters that help you to use your Pi for a specific purpose.

The initial chapters focus on the basics of setting up your Pi, Operating System installation/updates and setting up the networking. This forms a good base to then explore the remaining chapters.

The next set of chapter focus on a specific use of the Pi. The chapters range from:

  • Using the Pi as a Web Application Server
  • Setting up a File Server
  • Setting up a Game Server
  • Media Center
  • and even a Bit Coin mining machine (Hope you get lucky with that one!)

For households that have multiple devices, setting up a File Server or Game Server powered by your Pi is a great way to streamline things. In fact, you could jump to any chapter, if the specific purpose of that chapter is what you want to use your Pi with.

The instructions in each of the chapters are very precise. Right from downloading the software, configuring and running it, the instructions are good and focus just on the task, which is how it should be for a book of this kind.

Overall, this is a good book to explore practical uses that you could put to use immediately for your Pi.

Posted in Books, Personal, Reviews | Leave a comment

Hello Developer

There has never been a better time to be a developer. I believe this statement will remain true irrespective of the times we live in.

Large-Crowd-537x402

As a developer today, it is important to look at the full stack when developing applications today. This includes :

  • Web client
  • Native client (Android / iOS / etc)
  • Server side. Yes. You need the server too to power your mobile application functionality.

And not just that, it is important to understand design. Design is increasingly becoming an area that Developers need to understand and be part of, to create applications that not just wow your users but also make it intuitive to use.

As part of its Developer outreach, Google has teamed up with Udacity to provide several courses that address each of the above areas. These courses in my opinion are supported by best in class tools, teachers and materials and if you were looking to start off, these are great resources.

Here are the courses:

  1. Android Development
  2. UX Design for Mobile Developers
  3. Developing Scalable Apps on App Engine (PaaS)
  4. Website Performance Optimization
  5. There are couple of other courses, which have been there for a while and are still available:
    1. Mobile Web Development
    2. HTML5 Game Development

All the materials have been completely opened up for access by anyone. You do not have to pay the $150 / month. Just sign up and go for the Courseware link.

I recommend these courses strongly and hope you do take them. For inspiration, check out Reto Meier’s article titled “Enabling the next 50 Million Developers” and build apps for all.

Posted in Android, Cloud Computing, HTML5, Mobile | Leave a comment

Dive into HP IDOL OnDemand APIs

The future lies in processing data and deriving some value from it. Often, the process is tedious and could involve multiple sources of data, images, videos and more to link together.

hpidol

HP IDOL On Demand is a great set of APIs that is made available by the HP Cloud Platform that make things much easier for the developer.

Check out my article at ProgrammableWeb that goes into the details of the HP IDOL OnDemand APIs and code snippets to get started on them today.

Posted in APIs, Cloud Computing, Personal, Reviews | Leave a comment