Category Archives: grails

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)

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 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 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 […]

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 […]

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/messages.properties Add a message code at the bottom of the Spanish properties file: grails-app/i18n/messages_es.properties 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 […]

How to change the default port where your Grails App runs?

If you create a Grails 3 app and run it; it will start at port 8080. If you want to start it at a different port add to your application.yml the next block: And voila: Do you like to read about Groovy/Grails development? Yes, then Subscribe to Groovy Calamari a weekly curated email newsletter about the Groovy ecosystem […]

How to install new Relic in a Grails 3 app?

Recently I wanted to install new relic in a Grails 3 app which I distribute through Elastic Beanstalk. One of the steps described in the new relic documentation is: In your WAR file, add the newrelic.jar and newrelic.yml files to WEB-INF/lib/. How to do that in a Grails 3 application? Create a folder in the […]

How to customize the war name generated by “grails war” command?

If I run: Note how the grails war command uses by default the production environment. See the generated output: I can explicitly tell the command to use a different environment The generated war file uses the same naming: I want to change the default naming slightly. I want to add the environment to the name. […]

How to force IntelliJ IDEA to run Grails tests in the Test Environment

I recently stumbled across the next issue.  I was running a Grails 3 integration test in IntelliJ IDEA 15.0.3: My test was running in the development environment instead of in the test environment! Why is this happening? Alvaro Sanchez Mariscal pointed me to the issue in the Grails Slack Channel. The problem with running tests from IDEA is that IDEA […]

How to run Grails 3 App from IntelliJ with runtime reloading

It is easy to run a Grails 3 App directly from IntelliJ. Just click the green arrow in Application.groovy However, if you execute it without turning off bytecode verification the runtime reloading will not work. Fortunately is easy to turn off the bytecode verifier. Edit the configuration which was generated once you run the app […]

Validate a single field in a Grails 3 Domain class

Sometimes you have a domain class with multiple fields and you would like to test a single constraint. Create a Grails app test-app Add a firstName, lastName and age to the Person domain class Add the next test to validate the age constraint: Test fails: By default domain class’ fields have the constraint nullable: false. […]

Grails 3 web vs web-api profiles

Grails 3.0.5 was released September the 4th. I found this in the release notes: This release features the first version of the web-api profile for creating REST applications. This profile will evolve further in Grails 3.1 I am currently using Grails 3 for a REST API; web-api profile seemed tailor specifically to me.  So I went […]

webr00t

büyük meme pornoları