Mapping options for an Enum in a Grails Domain class

The next example illustrates the different options to map an enum. Given the next code: For enumType `ordinal` The enum will be mapped in the database as: ID VERSION NAME STATUS 1 0 Grails 3 – Step by Step 0 2 0 Grails 3 – A practical guide to application development 1 3 0 Falando […]

Grails War is a runnable JAR

Do you know you can run a Grails generated WAR with `gradle assemble` with `java -jar`?. Let me show you:

Debug Grails Plugins load order

Grails documentation talks about Understanding Plugin Load Order and controlling it with the use of loadBefore and loadAfter properties. It is easy to debug the plugin load order as well. Add this line to your grails-app/conf/logback.groovy file. logger(‘grails.plugins.DefaultGrailsPluginManager’, INFO, [‘STDOUT’], false)

Preview of Groovy 3

This blog post is a translation of @daniel_sun‘s post, originally posted in Chinesse. The next section will focus on the new parser “Parrot” features coming to Groovy 3. If you wish to be able to get yourself back and forth, follow the steps below to start Groovy 3’s groovy console to try these new features: […]

My first day at OCI

Yesterday I joined OCI Grails team. I am thrilled!. What better place to continue developing my Grails career. But let me reflect how I got here. 6th of July, 2011. This was the first time I heard about Grails. I was organizing a local meetup called Iniciador Guadalajara. We had the pleasure to be joined […]

How to use Groovy default parameter values to implement retry functionality

Lets say you have a class which depends on another component. The component ( for example a remote call ) sometimes fails. You want to execute a method with a number of retries. Groovy supports parameters with default values and we are going to leverage that capability and recursion to achieve a retry functionality. I […]

How to run Grails 3 tests within IntelliJ

This post explains how to open a Grails 3 App with IntelliJ as described in the Grails 3 IntelliJ Quickcast by Jeff Scott Brown First, force IntelliJ to run Grails tests in the test environment.

How to integrate Chart.js to load Dynamic JSON data in a Grails 3 application?

This is a translation of the post Intégrer Chart.js avec des données dynamiques JSON dans une application Grails 3 by Bertrand Goetzmann This Gist Responsive Chart.js Example with AJAX callback inspired this article. A HTML snippet which includes JavaScript. It demonstrates how to display a graph of the library Chart.js with JSON data obtained asynchronously […]

How to debug a Grails 3 App with IntelliJ?

This post explains how to debug a Grails 3 App with IntelliJ as described in the Grails 3 IntelliJ Quickcast by Jeff Scott Brown Checkout IntelliJ IDEA Debug documentation. Remote Debugger Alternatively, you can run your app with –debug-jvm flag and then attach a remote debugger to it. In order to attach IntelliJ as a […]

How to run a Grails 3 App with IntelliJ?

This post explains how to run a Grails 3 App with IntelliJ as described in the Grails 3 IntelliJ Quickcast by Jeff Scott Brown Using Application.groovy It is easy to run a Grails 3 App directly from IntelliJ. Execute the main method in Application.groovy. Just click the green arrow. Please, make sure you turn off […]

How to open Grails 3 App with IntelliJ?

This post explains how to open a Grails 3 App with IntelliJ as described in the Grails 3 IntelliJ Quickcast by Jeff Scott Brown Lets assume you already have a folder which contains a Grails 3 app. For example you cloned a Grails 3 project from a git repository or you created an app from […]

How to access Cookies with Geb?

Lets say we visit the Codemotion agenda; an upcoming Conference in Spain. We can check whether the website stores any cookies. As shown below it does: Let say we want to access those cookies with Geb. Web Driver to the rescue. Geb builds on the WebDriver browser automation library, which means that Geb can work […]

Swift vs Groovy – Types

Getting started Swift types Int Integer, whole number that does not containing any floating point information. Float 32bit number with floating point information Double 64bit number with floating point information Bool true or false String represents text Character Single unicode character There are more types but those are the most common in Swift. Type Naming […]

How to execute Geb with different browsers

Add Groovy dependency to build.gradle Add Gradle wrapper add Geb, Selenium, Drivers and Spock depependencies to build.gradle Create a test src/test/groovy/gebwebbot/greach/LegalSpec.groovy We are going to create a Geb.Config file to leverage Geb environment sensitivity. vi src/test/resources/GebConfig.groovy Pass Java system properties from the command-line to the gradle test task. In order to do that modify our […]

How to start / stop a EC2 instance with Groovy

Groovy is a great language for scripting. As a JVM language, it allows us to use many Java libraries already available. In this project we are going to start and stop a EC2 instance from a Spock test. Lets create a Gradle project with the Groovy plugin. Add Spock dependencies and AWS Java SDK. Lets […]

Obtain current page html source?

Geb manual: Geb builds on the WebDriver browser automation library, which means that Geb can work with any browser that WebDriver can. With WebDriver is easy to obtain the page source. Lets do a test to verify it. Lets start by creating a Gradle project with Groovy Add Groovy dependency to build.gradle Add Gradle wrapper […]

How to log from a none Grails Artifact

Create a grails app with the rest profile: Create a controller grails-app/controllers/lognongrailsartifact/TestController.groovy Create a Groovy Class src/main/groovy/lognongrailsartifact/NonGrailsArtifact.groovy; not a grails artifact. Note: Grails artefacts get log auto-injected. You will need to inject it manually in this class. Edit grails-app/conf/logback.groovy Run the app Invoke the controller And you will see the log statement: Soeren Glasius pointed […]

How to output CSV from a Grails 3 Controller

Create an app with the default web profile. Enter the grails console Create a domain class Add a couple of properties to the domain class In grails-app/init/BootStrap.groovy add a couple of domain class instances. The BootStrap init closure runs when the app starts. Create a controller This is the controller content: Several things about the […]

Setup / Cleanup Inheritance

Craig Atkinson‘s talk at GR8Conf US Intro to Spock and Geb claimed the next about Spock Cleanup / Inheritance. Might have a hierarchy of test classes for DRY common test code Spock runs the base class setup first Then goes down the inheritance chain cleanup is the reverse, starting at test class then going up […]

Hidden Content and Mouse over Events

Lets say we have an HTML page with content hidden until we place the mouse over it. It will look like this: And this is the html If I try to fetch the content with Geb, it will fail because it is hidden. Next test fails. We have several alternatives: A. Call a JS method […]

User Agent Spoofing

As often happens on the internet there is already a website to answer your question. If you would like to know what’s your user agent just visit If you run Geb with PhantomJs your user agent will identify you as running PhantomJs. You may be blocked because of that. Fortunately it is easy to […]

How to split loads between webbots?

Lately, I am coding a lot Webbots. Sometimes you need to split the load between different machines. Actual physical machines. Lets same you you have 6 machines at your disposal. Also, lets assume you know the total size of the elements which you want to process in parallel. For this example lets say 50 items […]

How to run Geb with PhantomJS Driver in desktop size

If you are developing your Geb programms with Firefox or Chrome driver, they will probably be running in a traditional desktop resolution. You may be puzzled when your tests fail in PhantomJS driver. Why? After further investigation you will probably realise that the tests are failing because the code you developed will only work when […]

How to ignore a Spock feature method in Grails 3 while running on Jenkins

It is easy to ignore a test only if the test is run in a particular environment thanks to the @IgnoreIf Spock annotation. If you run your tests in Jenkins, it is probable that the tests are being run by a user called jenkins. Thus, you can ignore a test in a Jenkins Job easily: […]

How to use a Groovy trait to output any class as csv?

The next example shows how to use a Trait to output a CSV string for any Class which implements the trait The next Spock test will pass: This Trait can be used for any class which you wish to output as a comma separated value. Useful to export information to be sued in Excel or […]

¿Cómo importar un archivo CSV en Excel?

Las siguientes capturas de pantalla muestra como importar un archivo CSV en Excel 2010. CSV es el acrónimo en inglés de Comma Separated Value. En español se suele utilizar el termino archivo separado por comas. 1. El primer paso es descargar el archivo CSV en un directorio fácilmente localizable de nuestro ordenador. 2. Ejecutar Excel […]

Groovy Sorting

This post is a transcript of this video: How Synctatic Sugar helps simplify common tasks in Grails Programming? | Grails Conf 2015 from TO THE NEW Digital on Vimeo. Passing false to sort will not modify the original list and return a new sorted list instead. This is the result: We can base a closure […]

How to change the server url of a Grails 3 App?

Sometimes you need to configure the exact server url (via domain name or ip address) of your Grails app. It is easy do it with a small configuration in your grails-app/conf/application.yml Do you like to read about Groovy/Grails development? Yes, then Subscribe to Groovy Calamari a weekly curated email newsletter about the Groovy ecosystem which I write 

How to change the default locale of your Grails 3 app?

The default welcome screen is shown: Add a message code at the bottom of grails-app/i18n/ Add a message code at the bottom of the Spanish properties file: grails-app/i18n/ Edit the file grails-app/views/index.gsp. Replace the line: with: If you start the app now, you will still the same html as before. Edit the file grails-app/conf/spring/resources.groovy and […]

How to create a multi project build with Grails 3 (apps and plugins)?

Updated to 3.2.8 Back in February I wrote a post about multi-project build. Since then, Graeme Rocher did a great Quickcast where he explains it much better. Because of that I have reviewed this post to include all the points covered in the video. Feel free to view the video or follow the post. Creating […]

JWT, the walking dead, of Spring Security REST for Grails plugin

This post continues with the code generated in the post: how to use a Trait to encapsulate Spring Security core functionality in a Grails 3 app First lets add the dependency to the Spring Security REST for Grails plugin to build.gradle Run the app grails run-app and you will be able to login and get […]

How to use a Trait to encapsulate Spring Security Core functionality in a Grails 3 App?

Add one dependency to your build.gradle as shown below to install Spring Security Core Plugin Lets create the security-related domain classes: Add a default user to grails-app/init/BootStrap.groovy Create a Controller which will return the name of the logged user: The controller code could be something like this: If we start the app and hit the […]

How to change the default port of a Grails 3 App

By default a Grails 3 app will start in the port 8080. It is easy however to configure a different port. Edit grails-app/conf/application.yml and add the next snippet at the bottom of the file. Next time you run the app, it will listen in the port 8090.

How to secure your Grails 3 API with Spring Security REST for Grails?

For this post I will continue reusing the code I created in the How to use Spring Security Core to Secure your Grails 3 app post In this post we are going to expose our app product announcements as JSON API and secure it with Spring Security REST for Grails plugin. Lets create a service […]

How to use Spring Security Core to Secure you Grails 3 App?

Spring Security Core plugin is probably the most famous security plugin in the Grails ecosystem. Lets create a simple app to publish product announcements: I create a domain class to store the product announcements. I add a message field to store the announcement and a dateCreated field to use Grails autoTimestamp capabilities. Add some ProductAnnouncement […]

How to log SQL statements in a Grails 3 app

I add a message field to my domain class since I need to announce stuff. Add some ProductAnnouncement messages when the application starts. To do that modify grails-app/init/BootStrap.groovy Now If I start the app, I don’t see any SQL output. I guess the .save() call did an insert but I have no visibility. How can […]