Tag: Grails

10 Posts Found

Add JAR to Local Maven Repository

Posted: 5/18/2017 6:48 PM

If you've obtained a JAR file that is not available in an existing Maven repository, you can add it to your local Maven repository with the following command. Make sure that all of your options are surrounded by double-quotes:

mvn install:install-file "-DgroupId=org.mozilla" "-DartifactId=jss" "-Dversion=4.2.5" "-Dpackaging=jar" "-Dfile=jss-4.2.5.jar"

Enable Hibernate SQL Logging in Grails

Posted: 5/18/2017 6:08 PM

It's often useful when debugging a Grails application to be able to see the exact SQL that is being executed in the database.

If you're using GORM, you can modify your /grails-app/conf/application.yml file with the following settings. Each Hibernate statement that is executed will be outputted to the standard console.

    logSql: true
    formatSql: true

Hibernate Error: @P0 Syntax Error

Posted: 5/18/2017 6:02 PM

Grails domain classes using GORM offer the dynamic finders Class.findByXXX() and Class.findAllByXXX(max: 123), which will retrieve 1 record and 123 records, respectively.

On SQL Server 2012 or higher, attempting to call one of these functions will throw a Hibernate error "Invalid syntax @p0". This is because you need to add an additional configuration option to your /grails-app/conf/application.yml file dataSource section:

dialect: org.hibernate.dialect.SQLServer2012Dialect

Use Environment Variables in application.yml

Posted: 5/14/2017 9:29 AM

A convenient method of configuring parameters in a Grails app application.yml file is to use system environment variables instead of hard-coding values.

The syntax for an environment variable is:


Custom-Named Grails WAR Files

Posted: 5/6/2017 2:22 PM

Gradle provides the ability to customize the name of the WAR file that is generated from the Grails war command.

Grails uses the war gradle plugin, which specifies the following pattern to create the archive name:


To customize the name of a generated WAR file, add a war {} closure to the end of the build.gradle file. To remove a property from the name (such as the version), set it to an empty string. You can also include the name of the environment that the WAR file is being generated for by retrieving the Java system property grails.env. The name of the current project is rootProject.name and is the default value for baseName.

String env = System.getProperty("grails.env") ?: "production"

war {
    version ""
    baseName rootProject.name
    appendix env

Change Grails Internal Tomcat Port

Posted: 4/30/2017 11:12 AM

By default, the grails run-app command, as well as running a Grails WAR from the terminal or as a Windows service, creates an instance of Tomcat on port 8080. To change this, edit the /grails-app/conf/application.yml file and create a new server section with the port number that you want:

    port: 9001

Configure JVM Garbage Collection Logging

Posted: 4/10/2017 2:26 PM

When your application gets to be a certain size, you'll have to enter the world of Java Garbage Collection, and analyzing memory usage to better determine needs and improve performance.

Part of that analysis is enabling Garbage Collection logging, so that you can then run the log through an analysis tool like GCEasy.io to get an idea of what's going on.

Add the following JVM options to the end of your launch string. In the example below, the file that's generated will be called gclog.txt.


Intelli-J Error: "No Groovy SDK Defined"

Posted: 3/27/2017 2:35 PM
  1. Right-click on the root of your Grails project and select "Add Framework Support".
  2. Select "Groovy".
  3. The dropdown menu next to "Use library" will allow you to choose a Grails library.
  4. If the "Use library" dropdown menu is empty, click "Create" and choose your Grails library directory. If you have installed Grails through SDKMAN, it will be located at: /Users/{username}/.sdkman/candidates/grails/current/ where {username} is your username.
  5. To remove an old version of Grails: Select File -> Project Structure -> Global Libraries. Delete the missing Grails version.

Grails Error: Error occurred running Grails CLI: No profile found for name [web].

Posted: 12/28/2016 1:03 PM

Sometimes after upgrading the version of Intelli-J that I'm using for development, when I try to run the command-line grails program, I receive the following error message:

Error occurred running Grails CLI: No profile found for name [web].

After searching around the web, I found that this was due to a problem with the build/.dependencies file located within your Grails project root. If you delete or rename this file, then run grails again, the dependencies will be corrected and you can run your app.


Default Grails GORM Domain Class Failures to Display

Posted: 11/29/2016 3:49 PM

By default, when a GORM .save() function call fails, it fails silently. If you want it to always throw an error, add this to your /grails-app/conf/application.yml file at the bottom.

    failOnError: true