nimavat.me

Java, Groovy, Grails, Spring, Vue, Ionic + Fun blog

Gradle - Adding external directory to classpath during development

|

We are using external config plugin for grails 3 which is configured to use a configuration file from classpath

    grails.config.locations = ["classpath:app-config.groovy"]

I wanted to override the datasource and some other configuration for development environment without needing to make change to project configuration which is checked into git so that i dont commit that to git by mistake. In order to do that, i required to add an external directory to gradle classpath where i can put the app-config.groovy file so that it can be picked up by external config. Below is how it can be done.

File build.gradle 

    dependencies {
        if(project.hasProperty("extraClasspath")) {
            provided(files(extraClasspath))
        }
    }

File gradle.properties or ~/.gradle/gradle.properties so that it can be shared among all projects.

    extraClasspath=/Users/sudhir/.grails/conf

Now I can put the app-config.groovy file inside ~/.grails/conf and it will be available in classpath during development. Note the directory is added as provided dependency so it will not be packed into the jar or war.