How I Use the Vertabelo API With Gradle

One of the exciting moments in a programmer’s life is to leave legacy code behind and have fun with some new, fresh and cool tools. Today I have just such an opportunity – I’m creating the structure of a new project in Java.

What is Gradle?

Gradle is an open source build automation system. It can automate the building, testing, publishing, deployment and more of software packages or other types of projects such as generated static websites, generated documentation or indeed anything else.

Learn more about what makes Gradle a compelling choice for build automation.

One of the exciting moments in a programmer’s life is to leave legacy code behind and have fun with some new, fresh and cool tools. Today, I have just such an opportunity – I’m creating the structure of a new project in Java.

First of all, let choose the build system. There’re plenty of them: Ant, Maven, Make. Well, let’s try something better: Gradle. That build automation tool with a clean and simple format of configuration written in Groovy DSL became a real competitor to Maven.

Installing Gradle for Ubuntu users:

It’s recommend to install the newest version:

  • download and unzip the archive from the official page: Gradle
  • set GRADLE_HOME environment which points to the unpacked directory
  • add GRADLE_HOME/bin to your PATH environment variable

Test your installation:

Getting started using Gradle is quite simple – just create build.gradle in a project directory and add only one line:

Add HelloVertabelo.java to src/main/java directory:

and run:

Your application has just been built.

Now let’s think about the application database. Creating it by hand? Not a good idea. Vertabelo? Yes, that’s better. First impressions with Vertabelo are quite promising. I want Gradle to download the model during the build (for example to create the database physical structure). How do I do that? Well, I’ve got a solution already. You need to write the task in Gradle. It’s not complicated. The syntax of Gradle files is Groovy DSL which will be familiar to Java programmers. Additionally, you can invoke ready-to-use ant tasks which simplify the code. Just add the text below to build.gradle file:

Remember that there’re two parameters required to run this task properly:

  • the variable ‘git’ in the task is a identifier of your model in Vertabelo, which you can find in the Model details panel:

    Vertabelo Model details

  • accessToken parameter set as the environment variable taken from Vertabelo => My Account

    Vertabelo API

The token should be set in that (Unix) way:

Finally, you can execute: gradle build

Done! The database model with the SQL file will be downloaded every time you build the application.

For more information about Gradle please visit the official page: Gradle.

For information about Vertabelo: Vertabelo.

Tools in this post

Redgate Data Modeler

Design, update, and manage database schemas

Find out more