Search code examples
grailsgrails3

What classspath is used for executing Grails' application.groovy


What classspath is used for compiling/executing Grails' application.groovy?

In my application.groovy, I instantiate a custom class (contained in a dependency's jar) and assign it to one of the config properties, like so:

environments {
    production {
        configProperty = new com.example.CustomClass()

I recently upgraded my application from Grails 3.1.5 to 3.2.2, and now this no longer works.

I receive an error like the following when I try to run grails run-app:

Error occurred running Grails CLI: startup failed:
script14788250424471597489853.groovy: 43: unable to resolve class com.example.CustomClass
 @ line 43, column 33.
        configProperty = new com.example.CustomClass()

(Notice that the code is in the production block, but I'm running in development (run-app). That makes me think it's the compilation of this script that is failing.)

So I'm guessing I just need to add my dependency (that contains the CustomClass) to the appropriate classpath, but I'm not sure which one.

I'm using gradle, and have the following in my build.gradle file, to pull in the dependency containing CustomClass:

buildscript {
    dependencies {
        classpath "com.example:custom-module:1.1"
// ...
dependencies {
    compile group: 'com.example', name: 'custom-module', version:'1.1'
}

Solution

  • The grails-app/conf/application.groovy file shouldn't reference application classes because it is read before compilation. If you wish to reference application classes in configuration please use grails-app/conf/runtime.groovy