Using Groovy 2.5 with Springboot

Simply changing the Groovy version in a Springboot Gradle project won't cut it. Trying to force the version with

compile('org.codehaus.groovy:groovy-all:2.5.0')

will result in errors building the project:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileGroovy'.
> org/codehaus/groovy/ast/MethodCallTransformation

The problem there is, that Springboot manipulates the dependencies via the plugin after the fact. So we end up with mixed 2.4 (which is the default for Springboot 2 right now) and the desired 2.5.

To solve this, we need to change the Groovy version as described in Customizing managed versions .

Instead of changing the version at the dependency, add the following at the top level of the build.gradle:

ext['groovy.version'] = '2.5.0'

References: