Over a million developers have joined DZone.

Grails Goodness — Changing Gradle Version

Sometimes we use Gradle plugins in our project that need a higher Gradle version, or we just want to use the latest version because of improvements in Gradle. We can change the Gradle version that needs to be used by Grails in different ways. Read on and learn how.

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

Since Grails 3, Gradle is used as the build tool. The Grails shell and commands use Gradle to execute tasks. When we create a new Grails 3 application, a Gradle wrapper is added to our project. The Gradle wrapper is used to download and use a specific Gradle version for a project. This version is also used by the Grails shell and commands. The default version (for Grails 3.0.12) is Gradle 2.3, which is also part of the Grails distribution. At the time of writing this blog post, the latest Gradle version is 2.10. Sometimes we use Gradle plugins in our project that need a higher Gradle version, or we just want to use the latest version because of improvements in Gradle. We can change the Gradle version that needs to be used by Grails in different ways.

Grails will first look for an environment variable GRAILS_GRADLE_HOME. It must be set to the location of a Gradle installation. If it is present, it is used as the Gradle version by Grails. In the following example we use this environment variable to force Grails to use Gradle 2.10:

$ GRAILS_GRADLE_HOME=~/.sdkman/gradle/2.10 grails

BUILD SUCCESSFUL

| Enter a command name to run. Use TAB for completion:
grails> gradle help
:help

Welcome to Gradle 2.10.

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

To see more detail about a task, run gradle help --task <task>

BUILD SUCCESSFUL

Total time: 0.861 secs
grails>

Another way to set the Gradle version is by changing the Gradle wrapper version. In our build.gradle file there is a task wrapper. This creates a Gradle wrapper for our project with the version that is specified in the file gradle.properties with the property gradleWrapperVersion. Let's change the value of gradleWrapperVersion to 2.10 and execute the wrapper task. We can change the value in the grade.properties file, the build.gradle file, or pass it via the command line:

$ ./gradlew wrapper -PgradleWrapperVersion=2.10
:wrapper

BUILD SUCCESSFUL

Total time: 2.67 secs

$ grails

BUILD SUCCESSFUL

| Enter a command name to run. Use TAB for completion:
grails> gradle help
:help

Welcome to Gradle 2.10.

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

To see more detail about a task, run gradle help --task <task>

BUILD SUCCESSFUL

Total time: 0.861 secs
grails>

It could be that we get an org/gradle/mvn3/org/apache/maven/model/building/ModelBuildingException exception after upgrading to a newer version. This is because the io.spring.dependency-management plugin is set to a version that is not supported by the newer Gradle version. If we change the version of the plugin to the latest version (0.5.4.RELEASE at the time of writing this blog post), then the error is solved.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:
groovy ,grails ,gradle

Published at DZone with permission of Hubert Klein Ikkink, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}